Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Image File to API Gateway #82

Open
nonamecodes000001 opened this issue Dec 10, 2018 · 1 comment
Open

Upload Image File to API Gateway #82

nonamecodes000001 opened this issue Dec 10, 2018 · 1 comment

Comments

@nonamecodes000001
Copy link

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?

@MohammadAlavi1986
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants