FileSystemServiceProvider.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Support\Facades\Storage;
  5. use League\Flysystem\Filesystem;
  6. use League\Flysystem\Local\LocalFilesystemAdapter;
  7. class FileSystemServiceProvider extends ServiceProvider
  8. {
  9. public function boot()
  10. {
  11. Storage::extend('s3', function ($app, $config) {
  12. $adapter = new \League\Flysystem\AwsS3V3\AwsS3V3Adapter(
  13. new \Aws\S3\S3Client($config),
  14. $config['bucket'],
  15. $config['root'] ?? ''
  16. );
  17. return new class($adapter, $config) extends Filesystem {
  18. protected $config;
  19. public function __construct($adapter, $config)
  20. {
  21. parent::__construct($adapter);
  22. $this->config = $config;
  23. }
  24. public function url($path)
  25. {
  26. return "/api/download?filename={$path}&bucket={$this->config['bucket']}";
  27. }
  28. };
  29. });
  30. }
  31. }