浏览代码

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

刘学玺 3 月之前
父节点
当前提交
16ce4da927
共有 1 个文件被更改,包括 37 次插入0 次删除
  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']}";
+                }
+            };
+        });
+    }
+}