• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Upload file using pre-signed url via NodeJS

New Here ,
May 17, 2023 May 17, 2023

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})
    }

 

 

TOPICS
AWS , Document Generation API , Node.js SDK , PDF Services API , REST APIs

Views

374

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources