I am trying to upload files to Amazon S3 with a presigned url with javascript fetch() as following(copy past from the chrome Developer tool)
fetch("https://.....amazonaws.com/.../copy.mp3?AWSAccessKeyId=...&Signature=...&Expires=1631443785", {
"headers": {
"content-type": "audio/mpeg",
"sec-ch-ua": "\"Google Chrome\";v=\"93\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"93\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\""
},
"referrer": "http://localhost:3000/",
"referrerPolicy": "strict-origin-when-cross-origin",
"method": "PUT",
"mode": "cors",
"credentials": "omit"
});
and it returns the following error "SignatureDoesNotMatch":
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided.
Check your key and signing method.</Message>
<AWSAccessKeyId>...</AWSAccessKeyId>
<StringToSign>GET 1631443785 ..../copy.mp3</StringToSign>
...
</Error>
The StringToSign
in the error says it's a "GET" request while I think that I am sending a PUT with fetch().
Besides, I try to run $curl
like:
$curl --request PUT --upload-file copy.mp3 https://....'
and it works.
Anything I am doing wrong here?
Thank you in advance.. I have been blocked here for 2 days :(