【发布时间】:2016-03-18 00:53:18
【问题描述】:
为什么我会从 S3 Amazon Pre-Signed Url PUT 请求中收到 SignatureDoesNotMatch 错误?
我正在使用 AWS Javascript SDK 生成签名的 putObject url,并使用 Dropzone.js 通过 jQuery Ajax PUT 请求发布来管理文件上传。
上传工作使用curl -v -T <IMAGE> <PRE-SIGNED-URL>。
请求:
// Send uploads to s3 signed urls.
// @param res [Object] of signed-url's for image files.
function sendFiles(res){
res.forEach(function(signedUrl){
// Get file for associated Dropzone queued file.
var file = returnFile(signedUrl.options.id);
// signedUrl.url returns:
// https://bucket.s3-us-west-1.amazonaws.com/path/(key:filename)Type=image%2Fjpeg&Expires=1449874843&Signature=####&x-amz-acl=public-read-write`
$.ajax({
url: signedUrl.url,
type: 'PUT',
data: file.upload,
contentType:'multipart/form',
dataType: 'json',
complete:function(data){
console.log("Done", data);
},
error:function(data){
console.log("Error", data);
}
});
});
}
回复:
<Code>
SignatureDoesNotMatch
</Code>
<Message>
The request signature we calculated does not match the signature you provided.
Check your key and signing method.
</Message>
【问题讨论】:
-
我遇到了这个问题,直到我意识到预签名的 URL 需要进行 URLDecoded... (?)
-
@Julian 有趣,我现在正在阅读article 关于您的
URLDecodeFormat()建议。确实有这个可能,我会试试的。 -
对您的建议感觉非常好。 RFC 3986 说
-字符不能被转义,我使用 uuid v4 签名作为我的密钥9d8bd4d6-9293-4432-a3f5-fa7119c3d493,目前正以9d8bd4d6%29293%24432%2a3f5%2fa7119c3d493发送。 -
@Julian 不幸的是,这不起作用。我从 uuid 字符串中剥离了
-字符并在其上运行decodeURIComponent(url),因为这是 javascript。
标签: javascript jquery ajax amazon-s3 dropzone.js