S3 Flysystem返回文件密钥,但是size方法抛出“未找到”

时间:2018-08-30 20:35:57

标签: php laravel amazon-s3

我可以使用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中发生了什么事情,它可以检索文件列表,但不能检索文件/对象本身的方法?

1 个答案:

答案 0 :(得分:-1)

我不知道这是否适用于s3,所以您可以尝试

    $datas = collect(Storage::disk('s3')->files($cp->s3DirectoryPrefix))
                        ->mapWithKeys(function($file) {
                            return [$file => Storage::disk('s3')->size($file)];
                        });