1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?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'] ?? ''
- );
- $filesystem = new Filesystem($adapter);
- return new class($filesystem, [], $config) extends FilesystemAdapter {
- protected $config;
- public function __construct(FilesystemOperator $adapter, array $visibility = [], array $config = [])
- {
- parent::__construct($adapter, $visibility, $config);
- $this->config = $config;
- }
- public function url($path)
- {
- return "/api/download?filename={$path}&bucket={$this->config['bucket']}";
- }
- };
- });
- }
- }
|