I'm trying to upload a file to S3 via a pre-signed URL. I've verified that the URL indeed works by testing it with curl
curl --request PUT --upload file {filename} "{url}"
It pushes it up there A-OK.
However, when trying it from javascript, I get this message:
The request signature we calculated does not match the signature you provided. Check your key and signing method.
I've taken as many debugging steps as I can come up with -- for instance, making sure that the content-types and Content Lengths match between the pre-signed url and what I actually try to upload.
I found this SO Thread And tried everything in there:
- My Keys have no trailing spaces or slashes
- My bucketname doesn't have a slash in it.
- Tried URL encoding my key -- no difference
- Made sure my keyname is compliant
So, I'm at a bit of a loss. Could anyone identify what would be causing S3 to reject this request?
Javascript:
$(document).ready(function () {
$('[type=submit]').click(function (evt) {
evt.preventDefault();
console.log($('#id_attachment').get(0).files[0].size);
var reader = new FileReader();
reader.onloadend = function (evt) {
console.log(evt.target.result);
$.ajax({
url: 'https://bucketname.s3.amazonaws.com/simple.png?Signature=vYIEOmAay9v6zwB1cz78FhXv6Yo%3D&Expires=1416243285&AWSAccessKeyId=ACCESSKEY',
type: 'PUT',
contentType: "image/png",
data: evt.target.result,
success: function () {
console.log('Uploaded data successfully.');
}
});
};
reader.readAsBinaryString($('#id_attachment').get(0).files[0]);
});
});