aws4 icon indicating copy to clipboard operation
aws4 copied to clipboard

Upload Image File to API Gateway

Open nonamecodes000001 opened this issue 6 years ago • 1 comments

Is there a way to upload image files using aws4? I'm selecting the image file from the standard <input type="file"> and I would like to pass the image file to my API Gateway endpoint. However, I'm unfamiliar on how to sign the request with aws4 when the body of the request is a file object.

Any help?

nonamecodes000001 avatar Dec 10 '18 18:12 nonamecodes000001

Here's the code for signing and uploading a file to S3 via api gateway:

opts = {
  service: 'execute-api',
  host: 'xxxxxxxxx.execute-api.us-east-1.amazonaws.com',
  region: 'us-east-1',
  method: 'PUT',
  path: '/stage/resource',
  headers: {
    'Content-Type': 'image/jpeg'
  },
  body: fs.readFileSync('/Users/xxxxxxxx/Pictures/download1.jpeg')
};

request(aws4.sign(opts, { accessKeyId: 'AKIAXXXXXXXXXXXXXX', secretAccessKey: 'YYYYYYYYYYYYYYYYYYYYYY' }));

MohammadAlavi1986 avatar Jan 07 '21 12:01 MohammadAlavi1986