【问题标题】:AWS s3 File uploading failing via Laravel通过 Laravel 上传 AWS s3 文件失败
【发布时间】:2016-01-25 03:35:56
【问题描述】:

我正在我的一个控制器函数中运行一个 Laravel 应用程序,其中包含这样的代码:

$s3 = Storage::disk('s3');
$s3->put( $request->file('file')->getClientOriginalName(), file_get_contents($request->file('file')) );

我相信 Laravel 在后台使用Flysystem 连接到 s3。尝试执行这段代码时,我收到如下错误:

Laravel 文档并没有让我深入了解这个问题的发生方式/原因。知道这里发生了什么吗?


编辑:经过其他几个 stackoverlflow 线程后:

似乎问题可能与我的服务器的 DNS 更相关?我在 Linode 实例上的 ubuntu 14.04 上。我使用 Nginx 作为我的网络服务器。

【问题讨论】:

  • 给我输出:$request->file('file')->getClientOriginalName(), file_get_contents($request->file('file'))
  • $request->file('file')->getClientOriginalName() 返回 image.pngfile_get_contents($request->file('file')) 返回您在错误屏幕截图中的第 13 行看到的长输出
  • 试试这个:File::get((string)$request->file('file')) 并添加“使用文件”;在顶部.. 而不是这个:file_get_contents($request->file('file'))
  • 我的 SELinux 被禁用

标签: linux laravel amazon-web-services amazon-s3 dns


【解决方案1】:

您的 S3 配置似乎有误,因为它尝试使用的主机 s3.us-standard.amazonaws.com 在我的机器上也无法解析。您应该验证您是否已配置正确的存储桶 + 区域。

【讨论】:

    【解决方案2】:

    检查您的S3 API endpoints 是否正确。

    要消除权限(角色/凭据)和相关设置错误,请尝试从该服务器使用AWS CLI s3api 执行put-object

    aws s3api put-object --bucket example-bucket --key dir-1/big-video-file.mp4 --body e:\media\videos\f-sharp-3-data-services.mp4
    

    【讨论】:

    • 这个答案帮助我找到了问题。尽管 s3 文档声明 Amazon S3 renamed the US Standard region to the US East (N. Virginia) region to be consistent with AWS regional naming conventions. There is no change to the endpoint and you do not need to make any changes to your application. 我无法连接到 us-standard 区域。我不得不把名字改成us-east-1
    猜你喜欢
    • 2017-04-12
    • 2014-11-15
    • 1970-01-01
    • 2015-09-12
    • 2016-08-07
    • 2016-04-07
    • 2023-01-24
    • 2016-11-20
    • 2021-04-20
    相关资源
    最近更新 更多