我正在嘗試將 S3 Multipart Uploader 從 Laravel 8 升級到 Laravel 9,并按照檔案中的說明升級到 Flysystem 3,并且沒有依賴錯誤https://laravel.com/docs/9.x/upgrade#flysystem-3 .
我無法訪問底層 S3Client 來創建分段上傳。
// Working in Laravel 8
// Laravel 9 throws exception on getAdapter()
$client = Storage::disk('s3')->getDriver()->getAdapter()->getClient();
// Underlying S3Client is used to create Multipart uploader as below
$bucket = config('filesystems.disks.s3.bucket');
$result = $client->createMultipartUpload([
'Bucket' => $bucket,
'Key' => $key,
'ContentType' => 'image/jpeg',
'ContentDisposition' => 'inline',
]);
return response()
->json([
'uploadId' => $result['UploadId'],
'key' => $result['Key'],
]);
然而,Laravel 9 會拋出例外Call to undefined method League\Flysystem\Filesystem::getAdapter()。
我查看了 League\Flysystem 的源代碼和 Laravel 的更新,但似乎無法找出使用更新和訪問底層Aws\S3\S3Client.
我更大的專案正在使用一個分叉的 laravel-uppy-s3-multipart-upload 庫,可以在這里看到 https://github.com/kerkness/laravel-uppy-s3-multipart-upload/tree/laravel9
uj5u.com熱心網友回復:
這在 Flysystem AWS 配接器 github 問題中進行了討論:
https://github.com/thephpleague/flysystem-aws-s3-v3/issues/284
Laravel 中正在添加一個方法,將于下周二(2022 年 2 月 22 日)發布:
https://github.com/laravel/framework/pull/41079
解決方法
LaravelFilesystemAdapter基類是可宏的,這意味著你可以在你的AppServiceProvider:
Illuminate\Filesystem\AwsS3V3Adapter::macro('getClient', fn() => $this->client);
現在你可以打電話...
Storage::disk('s3')->getClient();
...您將擁有一個S3Client. (我喜歡宏!)
一旦下周二的版本可用,您就可以洗掉此宏。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428461.html
