首页 > 解决方案 > 通过 React 中的 signedUrl 上传 Amazon S3 (PUT) 的 403 禁止错误

问题描述

我正在尝试在 React 中使用 signedUrl 上传到 AWS S3:即使用户具有上传权限,我也会收到 403 错误(权限在用户组、Cors 配置和存储桶策略中设置)

主要上传代码如下:

      var options = {
        headers: {
          'Content-Type': fileType
        }
      };

      axios.put(signedRequest,file,options)
      .then(result => {
        this.setState({success: true});
      })
      .catch(error => {
        console.log("Line 214: ERROR " + JSON.stringify(error));
      })

我使用 PHP 在后端创建了signedUrl:

$cmd = $s3Client->getCommand('GetObject', 
   [ 'Bucket' => <bucket>,
     'Key' => <key> 
]); 
$request = $s3Client->createPresignedRequest($cmd, '+120 minutes'); 
$presignedUrl = (string) $request->getUri();

标签: reactjsamazon-s3uploadhttp-status-code-403

解决方案


推荐阅读