Why might I be getting a SignatureDoesNotMatch
error from a S3 Amazon Pre-Signed Url PUT request?
I am using the AWS Javascript SDK to generate the signed putObject
url and posting with a jQuery Ajax PUT request using Dropzone.js to manage file uploads.
Uploads work with curl -v -T <IMAGE> <PRE-SIGNED-URL>
.
Request:
// 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);
}
});
});
}
Response:
<Code>
SignatureDoesNotMatch
</Code>
<Message>
The request signature we calculated does not match the signature you provided.
Check your key and signing method.
</Message>
I found a solution. This took two modifications. I hope someone could explain them better.
First
I had to run decodeURIComponent()
on the returned s3 signed url string from the aws-sdk.
Second
I had to change three and add two new options to the ajax PUT request.
{
data: file,
contentType:'image/jpeg',
dataType:"text",
cache : false,
processData : false
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.