API Gateway - Post multipart\form-data

API Gateway does not currently support multipart form data. This is being considered for future development. In the meantime, you will need to modify your client to use multiple requests or a single one-part request.

Update: API Gateway now supports binary payloads. Simply define multipart/form-data as a binary media type for your API and proxy the payload directly to a Lambda function. From there you can parse the body to get your file content. There should be libraries available to help parse the multipart body (parse-multipart in Node.js for example).


I had same problem to integrate with my tomcat server, I found below changes needed to fix it.

  1. Add Content-Type in your api's HTTP Request Headers in api gateway by console or add it in open api documentation like

    {
        "/yourApi":{
            "post":{
                "operationId":"uploadImageUsingPOST",
                "produces":[
                    "application/json"
                ],
                "parameters":[
                {
                    "name":"Content-Type",
                    "in":"header",
                    "required":false,
                    "type":"string"
                },
                {
                    //Other headers
                }]   
            }
        }
    
  2. Above step also add Content-Type in your api's HTTP Headers of integration request, If not add it there also and add one more header Accept ='/' in api gateway by console or or add it in open api documentation like

    "requestParameters":{
        "integration.request.header.Accept":"'*/*'",
        "integration.request.header.Content-Type":"method.request.header.Content-Type",
        //Other headers
    }
    
  3. Set Content Handling as Passthrough in your api's integration request.

  4. Add multipart/form-data as Binary Media Types in your api's settings through console or by open api documentation

    "x-amazon-apigateway-binary-media-types": [
        "multipart/form-data"
    ]
    
  5. Deploy above changes to desired stage where you are going to upload image as multipart.

Api gateway will pass your multipart file as binary array and you can still use @RequestBody MultipartFile multipartFile in your controller and spring will parse this binary to multipart for you.


For those who still need some help, this is now officially documented:

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

To summarize, the steps are as follows:

  1. Go to the API Gateway settings tab for your API and add multipart/form-data to the binary media types section.
  2. Add Content-Type and Accept to the request headers for your proxy method
  3. Add those same headers to the integration request headers
  4. Re-deploy the API