Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting form-data and binary data through AWS API Gateway

I'm trying to POST "mutlipart\form-data" to my EC2 instance through AWS API Gateway, but I couldn't find a way to this. There is a way to post data using "application/x-www-form-urlencoded" and Mapping Tamplate to convert it to JSON but still posting a binary data like an image file is missing I guess. Is there anything I'm missing ?

EDIT:

I have found another way:

I convert the image to base64 string then POST it as with content type "application/x-www-form-urlencoded". By this way I'm sending whole image as string. After I got the message I can convert it back to image in PHP. Only down side of this I could find is when I convert image to base64 its size gets a bit bigger. Other than that, I couldnt find any other downside. If there is could you please share with me ?

like image 305
Can Atuf Kansu Avatar asked Dec 18 '15 22:12

Can Atuf Kansu


People also ask

How do you upload any type of binary file to S3 via API gateway?

To upload a binary file (image) to an S3 bucket using API Gateway, you must activate binary support for your API Gateway REST API. To allow your API to access your S3 bucket, you must also create an AWS Identity and Access Management (IAM) role.

Does AWS API gateway support multipart form data?

API Gateway can act as a passthrough, sending all data directly to a Lambda function. This makes it possible to send multipart/form-data to a lambda for processing.

What are the correct steps to deploy an API gateway in Amazon?

Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway . In the APIs navigation pane, choose the API you want to deploy. In the Resources navigation pane, choose Actions. From the Actions drop-down menu, choose Deploy API.


1 Answers

Api Gateway team here.

Binary data isn't supported at the moment, but it's on our backlog. Several customers have requested this.

Some customers have had success using the base64 util in the mapping templates which may get it working for you: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#util-template-reference

Other than that you'll have to wait for official support.

Edit

Binary support is finally here!!

like image 105
jackko Avatar answered Oct 21 '22 11:10

jackko