Browse Source

fixed:后台-规定上传接口返回url格式

刘学玺 3 months ago
parent
commit
16ce4da927
1 changed files with 37 additions and 0 deletions
  1. 37 0
      app/Providers/FileSystemServiceProvider.php

+ 37 - 0
app/Providers/FileSystemServiceProvider.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\Storage;
+use League\Flysystem\Filesystem;
+use League\Flysystem\Local\LocalFilesystemAdapter;
+
+class FileSystemServiceProvider extends ServiceProvider
+{
+    public function boot()
+    {
+        Storage::extend('s3', function ($app, $config) {
+            $adapter = new \League\Flysystem\AwsS3V3\AwsS3V3Adapter(
+                new \Aws\S3\S3Client($config),
+                $config['bucket'],
+                $config['root'] ?? ''
+            );
+
+            return new class($adapter, $config) extends Filesystem {
+                protected $config;
+
+                public function __construct($adapter, $config)
+                {
+                    parent::__construct($adapter);
+                    $this->config = $config;
+                }
+
+                public function url($path)
+                {
+                    return "/api/download?filename={$path}&bucket={$this->config['bucket']}";
+                }
+            };
+        });
+    }
+}