s3预先签名的url分段表单数据上传err:签名不匹配 [英] s3 presigned url multipart formdata upload err:signature does not match
问题描述
我正在从aws获取一个预签名的url,并使用它来请求(放置)一个zip文件.我得到的签名不匹配.
I am getting a presigned url from aws and using it to request(PUT) a zip file. I get signature does not match.
在获得预签名的网址时:
when getting presigned url:
const params = {
Bucket: myBucket,
Key: myKey,
Expires: 60*60,
ACL: '**-**-**',
ContentType: 'application/x-zip-compressed'};
在请求时:
const formData = new FormData();
formData.append('file', file);
formData.append('filename', file.name);
fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/x-zip-compressed',
},
body: formData
})
推荐答案
您在签名中使用的任何ACL
值也都必须以'x-amz-acl': '**-**-**'
的形式发送到请求标头中.
Whatever ACL
value you're using in the signature needs to also be sent in the request headers, as 'x-amz-acl': '**-**-**'
.
还要注意,S3 PUT
不会期望FormData
,它期望body
仅包含对象的原始字节 .这不是导致错误的原因,但是,一旦纠正了签名错误,就需要更改它,以获取有效且可用的上载.
Note also that an S3 PUT
does not expect FormData
-- it expects the body
to contain only the raw bytes of the object. This isn't the cause of the error, but once you correct the signature error, you'll need to change this, too, in order to get a valid, usable upload.
这篇关于s3预先签名的url分段表单数据上传err:签名不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!