【问题标题】:S3 Flysystem returns file key, but size method throws "Not Found"S3 Flysystem 返回文件密钥,但 size 方法抛出“未找到”
【发布时间】:2019-02-05 20:52:29
【问题描述】:

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

【问题讨论】:

  • 你需要给出bucket的完整路径...“content_properties”是主要的“bucket”吗?
  • 不是相关评论,因为适配器返回桶内对象的对象键。
  • “不是相关评论”,真的吗?任何 S3 PHP 适配器中的 size 函数都需要对象的完整路径,祝您好运。

标签: php laravel amazon-s3


【解决方案1】:

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

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

【讨论】:

  • 与问题无关。如上所述,size() 命令适用于其他存储桶中的对象,但不适用于此特定存储桶。
猜你喜欢
  • 2021-05-11
  • 1970-01-01
  • 1970-01-01
  • 2017-03-11
  • 2020-12-27
  • 1970-01-01
  • 2016-07-07
  • 1970-01-01
  • 2021-04-06
相关资源
最近更新 更多