How to pass binary data from lambda function to API Gateway - Amazon API Gateway p9
ฝัง
- เผยแพร่เมื่อ 6 ก.พ. 2025
- Welcome to part 9 of the tutorial series on Amazon API Gateway. In this tutorial, I have demonstrated how to pass binary data or file from lambda function to API Gateway which also includes how to download a file from S3 using API Gateway.
---
Support my work:
---
Patreon: / srcecde
PayPal: paypal.me/srcecde
Paytm | Gpay: 9023197426
---
Series Tutorial
---
Part 1: • Create API using AWS A...
Part 2: • Resources and Methods ...
Part 3: • Deploying and invoking...
Part 4: • How to validate reques...
Part 5: • How to validate reques...
Part 6: • How to upload binary f...
Part 7: • Configure path & query...
Part 8: • How to pass query para...
Part 9: • How to pass binary dat...
Part 10: • Pass binary data from ...
Part 11: • Download file using pr...
Part 12: • Upload file using pre-...
Part 13: • How to upload file wit...
Part 14: • How to create Usage Pl...
Part 15: • How to invoke API Endp...
Part 16: • How to enable CloudWat...
Part 17: • How to invoke lambda f...
Part 18: • Stage variable with la...
Part 19: • Stage variable with la...
Part 20: • Download file from lam...
Part 21: • SQS integration with A...
Part 22: • Video
Part 23: • Fetch message from SQS...
Part 24: • Delete message from SQ...
Part 25: • How to invoke API endp...
Part 26: • Upload file using HTML...
Part 27: • Invoke API endpoint us...
Part 28: • Canary release - Amazo...
Playlist: • Amazon API Gateway tut...
---
Another channel:
---
My Gaming Channel: / @gamepersonified782
---
Connect with me
---
Twitter: / srcecde
GitHub: github.com/src...
Facebook: / srcecde
Instagram: / srcecde
Thank you, sir. This was really helpful. I had this task to be done for a client of mine and didn't know how to achieve this. Thanks a lot!
Glad it helped! Please like, share & subscribe. :)
Great video, was stuck with this problem for a while, solved it thanks to you.
Glad it helped, Mkrtich Hovhannisyan! Please like, share & subscribe :)
@@SrceCde I did )) I got one issue though, when I return file content encoded in base 64 i get a long string of binary data and when I put it in src tag i can get the image, but when my lambda function is invoked by s3 object in frontend i get readable stream instead of the binary data. If you could give an advice that would be great.
Hi Sir, i we send the pdf data as binary rather base64 encoded for file upload, do we need to convert the pdf data to binary like 1 or 0 format and send string to end point.... Another question,... Sending the data for file upload do we need to do always bytes rather string?
you are really great. Giving us good content. All the best and keep posting.
Thank you so much. Please like, share & subscribe. :)
thanks worked fine. only thing is that downloaded file doesnt keep naming or extension (file type). is there a way to keep that?
Hi can you guide me how to implement content-type based routing using lambda
I love you. thank for your explain
Glad it helped! Please like, share & subscribe :)
Hi sir, when I call the API I got PDF data returned back but not triggering the download, any idea where I did wrong? Got something like this: %PDF-1.4
%����
1 0 obj
Hello Srce Cde, i followed your example to download a zip file but doesn't work. would you mind to tell me what i have to change to your code? thank you for your useful videos
Thanks for stopping by corsaro nero! I think you need to update the content type to application/zip or application/gzip at 12:14
However, at the same time, it's also a good idea to use pre-signed URLs to download a file. Please refer to this video for the same: th-cam.com/video/lv-XXk607xg/w-d-xo.html
I hope this helps. Please like, share & subscribe :)
@@SrceCde thank you so much, appreciate
I have an elasticsearch query from lambda that returns an s_3object as a string with bucket and key. I want to pass that string into another lamda function to get the binary image and a presigned URL. Do you have any ideas?
Thanks for stopping by Joshua Dixon. In that case, you can call another lambda function from your first lambda function or you can integrate the logic of generating a pre-signed URL in the same lambda function. I hope this helps. Please like, share & subscribe. :)
Thank you for replying. Can you do a video on Step Functions and Interation with Lamda Functions or API Gateway.
Hi Sir, your tutorial helped me a lot, can we stream large binary files using this method as it is showing me an error when I'm trying to do so.
Thanks for stopping by Hrishi! You cannot pass the payload more than 10 MB and that is the hard limitation. But you can use a pre-signed URL. I hope this helps. Please like, share & subscribe :)
Hi Chirag, Many thanks for uploading video on binary file download from s3. I tried using the same settings and instead query parameters I have hardcoded the bucket and file name in lambda function and fetch the object from S3 and tried to send as a response to api gateway but I am getting error saying not able to load pdf content. Can you please let me know what mapping template we have to use in integration response. I have used application/pdf
Withing Integration Response, we are not making any changes. And I would recommend you to follow each step thoroughly. Though, it's hard to say about the exact issue without looking at it. If you are still facing an issue, let me know. I will try to help you with quick teamviewer session.
@@SrceCde hi Chirag, I have found the issue and it's because of enabling binary media types. I have disabled now and it is working. Many thanks for publishing the above video and it's really helpful 😀
I'm glad that it's working. I will soon post the tutorial on how we can pass binary data using lambda proxy integration. And later, how to generate a pre-signed URL to download a file from S3 bucket. Please stay tuned for the same. Please like, share & subscribe. :)
@@saikrishnabejjanki8025 I have posted a tutorial on how to create pre-signed URL to download a file from S3 bucket using API Gateway. Please check: th-cam.com/video/lv-XXk607xg/w-d-xo.html
I hope it will be helpful. :)
Hey Chirag, thanks for this...I am struggling with one more issue on lambda. I am trying to send data (pdf stored on S3, which i am successfully able to access, this happens in one VPC) converted into base64 to an external API and getting an 'Internal Server Error' unable to understand the reason....This was working with a simple lambda without any vpc in the picture
Hi, How to make it generic, like for any file, What should be the content-type for this use case?
Thanks for stopping by Anirvan Sen. I think you can use multipart/form-data. I hope this helps. Please like, share & subscribe. :)
Sir how I pass array parameters in api get service
like
"search":["abc","def"]
any setting ?? it gives parsing error
it works if the service method was post but not support in GET method how I solve it
Please help
I am able to do it directly, not sure why you are getting the error. So basically ever step would be the same as he mentioned. No changes required. While passing file=content.pdf, just replace it with your “search”:[“abc”,”def”]. It should work. I am using postman and wrote file=“search”:[“abc”,”def”] and it worked fine
When i execute api endpoint i am getting internal server error . I have followed along and everything is ok could not find error yet
Plz if someone can help would be much appreciated
Thanks
Thanks for stopping by! You can debug the issue by
1. Checking the lambda function logs
2. Enable logging for the API & check the logs for any error: th-cam.com/video/N49Bp_bd93I/w-d-xo.html
3. Please check if you have configured the Content-Type under Binary media Settings of the API
I hope this helps. Please like, share & subscribe :)