aws4
aws4 copied to clipboard
Upload Image File to API Gateway
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?
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' }));