I am having a hard time trying to get a grasp on API Gateway Binary Support. How do I send upload a file together with a textual form data in a single multipart/form-data POST?
Asked
Active
Viewed 675 times
1
-
Where is the file being uploaded to after being received by API Gateway? – Michael - sqlbot Sep 30 '17 at 17:21
-
I'm uploading to Lambda in the following format... { "bucket": "EXAMPLE-BUCKET", "data": "EXAMPLE-DATA" }. Lambda will then upload the data to the required S3 bucket – ngzhongcai Oct 01 '17 at 00:56
-
1API Gateway doesn't parse or interpret the `multipart/form-data` structures... you'd have to parse the fields from the request body, after decoding it from base64, inside the Lambda function. https://stackoverflow.com/a/41770688/1695906 – Michael - sqlbot Oct 01 '17 at 15:30
1 Answers
1
Have you added multipart/form-data as one of the Binary Media Types in the API Gateway configuration (In the "Settings" tab)?
AWS API Gateway handles both binary data and text data and multipart/form-data is one of the binary data types.
The key thing you need to do is to leverage the Content-Type header, which is Content-Type: multipart/form-data; <boundary XXX>, to tell the gateway to handle your payload as binary data. After having multipart/form-data as one of the Binary Media Types, you just need to read the payload as a multipart form and there are plenty of libs that do this.
Youwithouto
- 21
- 2