Copy link to clipboard
Copied
I'm having issues trying to upload a local file using the presigned url. When I execute the `PUT` request I get an error
SignatureDoesNotMatch - The request signature we calculated does not match the signature you provided. Check your key and signing method.
Here's a snippet of my code.
Note* I extracted the amz query strings from generated uri to make sense of the values being passed and the replace function was needed because I received a malformed error due to the encoded characters.
export default async function uploadWordDoc(
request: VercelRequest,
response: VercelResponse
){
try {
const {dlUri} = await uploadDoclink("docuExample") as DocResponse
const {url, security_token, algorithm, date, headers, expires, creds, signature} = extract_amz_params(dlUri)
const formData = new FormData()
formData.append('file',createReadStream(join(__dirname,'..','/text.docx')))
const res = await axios.put(`${url}`,formData,{
headers: {
'Content-Type': "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
},
params: {
'X-Amz-Security-Token': security_token.replace(/\%2B/g,'\+').replace(/\%2F/g,'\/').replace(/\%3D/g,'\='),
'X-Amz-Algorithm': algorithm,
'X-Amz-Date': date,
'X-Amz-SignedHeaders': headers.replace(/\%3B/,';'),
'X-Amz-Expires': 3600,
'X-Amz-Credential': creds.replace(/\%2F/g,'\/'),
'X-Amz-Signature': signature
}
})
response.json({
msg: "Document still processing",
uploadResponse: res
});
} catch (e) {
console.log(e)
response.status(500).json({e})
}
Have something to add?