7
votes

I am trying to get the form data from a multipart/form-data POST to my ASW Lambda web service via API Gateway.

The HTTP POST has Content-Type "multipart/form-data" and body that is URL encoded. File data is also sent in this post (hence the multipart, I guess).

The web service needs to integrate with a thirdparty service, so changing the format of the POST isn't really an option.

I have seen this thread talking about converting the URL encoded data to JSON object for use in Lambda, but this doesn't do the trick.

I have also tried setting the Integration Request -> Mapping Templates for content type multipart/form-data to Input passthrough. This didn't help either.

I did come across another question about uploading a file using multipart/form-data, but since I'm not interested in the file, just the body, that answer didn't help.

Below find screenshot (sorry) of the captured post via runscope.

Post details

1
Can you show an example of the post body? - Ryan
@Ryan updated with screenshot of post. - Diederik

1 Answers

5
votes

If the goal is to use Lambda, you'll need to pass valid JSON to the function. Currently there isn't a way to JSON-ify data inside Api Gateway that comes in as non-JSON data.

Our short term fix (on our backlog) is to provide a variable in the mapping templates to grab the raw input of the request. That way you could do a simple JSON conversion using a template like:

{
    "body" : "$input.body"
}

or something like that.

Check out the mapping template reference for more info: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

Edit 4/7 - feature has been released as $input.body