123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Filesystem\FilesystemAdapter;
- use League\Flysystem\FilesystemOperator;
- 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'] ?? ''
- );
- $driver = new Filesystem($adapter);
- return new class($driver, $adapter, $config) extends FilesystemAdapter {
- protected $config;
- public function __construct(FilesystemOperator $driver, $adapter, array $config = [])
- {
- parent::__construct($driver, $adapter, $config);
- $this->config = $config;
- }
- public function url($path)
- {
- $filename = basename($path);
- return "/api/download?filename={$filename}&bucket={$this->config['bucket']}";
- }
- };
- });
- }
- }
|