1

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?

ngzhongcai
  • 1,793
  • 3
  • 23
  • 31
  • 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
  • 1
    API 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 Answers1

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.

Ref: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-configure-with-console.html