dozxos6346 2018-09-08 15:44
浏览 392
已采纳

使用AWS PHP SDK上传到AWS S3无法通过身份验证

I am using version 3.67.5 of AWS SDK PHP to upload files to S3. The code is in an Heroku dyno.

I've created the access keys, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, and set them as configuration variables in the Heroku instance. I know that they are there, because with getenv() I 've outputted them.

I'm using the following code:

  1. try {
  2. //Create a S3Client
  3. $s3Client = new S3Client([
  4. 'profile' => 'default',
  5. 'region' => 'some-region',
  6. 'version' => 'latest'
  7. ]);
  8. $result = $s3Client->putObject([
  9. 'Bucket' => 'some-bucket',
  10. 'Key' => $fileName,
  11. 'SourceFile' => $this->getParameter('photos_directory') . $fileName,
  12. ]);
  13. } catch (AwsException $e) {
  14. echo $e->getMessage() . "
  15. ";
  16. }

Still, uploading a file, it shows the following error:

request.CRITICAL: Uncaught PHP Exception Aws\Exception\CredentialsException: "Cannot read credentials from /app/.aws/credentials"

I've tested passing a new element 'credentials' in the constructor, like they do in theirs unit tests, and the error is the same.

  • 写回答

2条回答 默认 最新

  • dongri1989 2018-09-09 14:36
    关注

    The problem was in defining the profile as "default". When I removed the profile parameter, the error disappeared.

    When using the latest version, 3.67.8, the following error occurred:

    AWS HTTP error: Client error: `PUT https: // some-url` resulted in a` 403 Forbidden`
    

    Anyway, in my case, and in both versions, omitting the profile parameter was the solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

问题事件

  • 专家修改了标签 8月18日

悬赏问题

  • ¥15 vscode请求各位指导
  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部