我能够使用 league\flysystem 存储方法获取并列出 S3 中特定键/目录的文件:
$s3 = Storage::disk('s3');
$files = $s3->files($cp->s3DirectoryPrefix);
返回:
array( 0 => "content_properties/503a3468-d660-44f8-9edd-f10cd812f346/submaster_primary.mp4")
但是,当我尝试获取返回的文件的大小时,它会引发异常。
$size = $s3->size($files[0]);
League Flysystem FileNotFoundException
File not found at path: content_properties/503a3468-d660-44f8-9edd-f10cd812f346/submaster_primary.mp4
这只发生在某个存储桶上。其他存储桶不会引发异常,并且正确返回对象/文件的大小。
知道我做错了什么吗?桶上的某些特定设置?
使用相同的凭据通过 CLI 访问对象工作正常:
aws s3api head-object --bucket content-data-app-private --key content_properties/503a3468-d660-44f8-9edd-f10cd812f346/submaster_primary.mp4
aws s3api get-object --bucket content-data-app-private --key content_properties/503a3468-d660-44f8-9edd-f10cd812f346/submaster_primary.mp4 ~/Downloads/submaster_primary.mp4
这些返回正确的信息/内容。那么在 Flysystem 中发生了什么,它可以检索文件列表,但不能检索文件/对象本身的方法?
我不知道这是否适用于 S3,所以你可以尝试
$datas = collect(Storage::disk('s3')->files($cp->s3DirectoryPrefix))
->mapWithKeys(function($file) {
return [$file => Storage::disk('s3')->size($file)];
});