0
votes

I have requirement to upload images to s3 bucket from lambda function using serverless framework in node js.

I want to get image file from react app. So, How can I get image file from react app to lambda ao that I can upload it to s3 bucket using lambda.

I have user lambda-multipart-parser to upload. It is working in local environment but not working after deployed to aws. lambda-multipart-parser is able to parae request in local but unable to parse request after deployed to aws.lambda-multipart-parser is able to parse complete image in buffer array but afrer deployed, it is unable to parse complete image to image. There are missing buffer data after deployed.

Suggest me any good solution.

1
Why don't you just use presigned URLs for uploading images directly from your client app? - StefanN
For pre signed, I will have to send two request. One for pre signed url and second for uploading photo with that signed url from frontend. What if i want to upload image from backend only ? - Vaibhav Dhaduk
U don't see any issue with sending 2 request there. But if you really want to "optimize" that you can ask for that URL with the request for loading dynamic page data. Also signed URLs will work from the backend as well. - StefanN

1 Answers

0
votes

are you sure the lambda parser unable to parse the image? if it really isn't able then i would check the logs maybe you need more memory or a bigger timeout ( you can find how to do it here https://www.serverless.com/framework/docs/providers/aws/guide/functions/ ), if you just can't upload it from the lambda to the s3 bucket i would guess that you need to add IAM policies to give the lambda an authorization to upload an image to the s3 (https://www.serverless.com/framework/docs/providers/aws/guide/iam/).