我试图使用Lambda将图像上传器创建到S3存储桶。但是,当我尝试对从lambda生成的签名URL进行PUT请求时,我得到了403。
我已将lambda配置为能够使用s3:putObject和s3:putObjectACL,我也尝试将s3存储桶公开以允许对其进行读写,Everyone
并且还对s3存储桶以及API lambda触发端点启用了CORS 。
当我尝试从客户端HTML页面上载图片时,仍然收到403禁止信息。
函数是这样的:
const uploadS3 = async (uri) =>{
const file = new Image();
file.src = uri;
const url = "API-Endpoint to trigger LAMBDA";
fetch(url,
{
//fetches the signed url
method: 'GET',
mode:'cors',
})
.then((res) => res.json())
.then((response)=> {
console.log(response);
console.log(response.uploadURL);
// request to try to PUT image to s3 bucket using the signed url
fetch(response.uploadURL,{
method: 'PUT',
headers: {
"Content-Type": "image/png"
},
mode:'cors',
body: file
})
.then((res)=> console.log(res))
.catch((res)=> console.log(res))
})
.catch((err)=>console.log(err))
}
我要去哪里错了?非常感谢您的帮助!
在服务器端获取预签名URL以及在客户端使用预签名URL进行请求时,都需要以下标头
{ headers: { 'Content-Type': 'image/jpeg', 'x-amz-acl': 'public-read' } };
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句