【问题标题】:Laravel 5 upload files to s3 on wrong urlLaravel 5 在错误的 url 上将文件上传到 s3
【发布时间】:2018-02-01 05:40:25
【问题描述】:

我在 Laravel 5 中实现了将文件上传到 s3,当上传文件时它给出错误消息:Error execution \"PutObject\" on ......,我发现它的发生是因为尝试访问的 url 错误,网址是:

https://{buckets}.{s3 domain}/{buckets}/{filename}

,在 s3 域之前,为什么 laravel 将存储桶名称放在 url 上?正确的网址应该是

https://{s3 domain}/{buckets}/{filename}

,那么如何解决呢?

以下是我的代码:

>     $file = $request->file('file');
>     $fileName = $file->getClientOriginalName();
>     $savedFileName = '/test_buckets/' . date('YmdHis') . '_' . $fileName;
>     $s3 = Storage::disk('s3');
>     $s3->put($savedFileName, file_get_contents($file), 'public');     

【问题讨论】:

  • 请出示您用来生成网址的代码。
  • 权限设置好,报错是url错误。

标签: laravel laravel-5 amazon-s3


【解决方案1】:

通过从 $s3->put($savedFileName, file_get_contents($file), 'public') 中删除 'public' 来解决这个问题,它看起来像 bug -- 当有可选的第三个参数 'public' 时,它会添加url中域名前的bukets名称。

【讨论】:

    猜你喜欢
    • 2017-07-29
    • 2020-12-26
    • 2012-03-07
    • 2019-08-17
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多