I have an AWS API Gateway acting as a proxy to a backend service:
{
  "apiKeySource": "HEADER", 
  "name": "-", 
  "createdDate": 1513820260, 
  "binaryMediaTypes": [
      "application/zip", 
      "application/octet-stream"
  ], 
  "endpointConfiguration": {
      "types": [
          "EDGE"
      ]
  }, 
  "id": "-"
}
The integration definition is here:
{
  "integrationResponses": {
      "200": {
          "responseTemplates": {
              "application/json": null
          }, 
          "statusCode": "200"
      }
  }, 
  "passthroughBehavior": "WHEN_NO_MATCH", 
  "timeoutInMillis": 29000, 
  "uri": "http://${stageVariables.backend}:7000/{proxy}", 
  "connectionType": "INTERNET", 
  "httpMethod": "ANY", 
  "cacheNamespace": "iv06s3", 
  "type": "HTTP_PROXY", 
  "requestParameters": {
      "integration.request.path.proxy": "method.request.path.proxy", 
      "integration.request.header.X-Source-IP": "context.identity.sourceIp"
  }, 
  "cacheKeyParameters": [
      "method.request.path.proxy"
  ]
 }
I have an endpoint that generates a Zip file on the fly and returns it to the requester.
When I access the endpoint directly, the file is fine. When I access it via the API Gateway, it gets corrupted.
The corruption takes the form of bytes in the original file being converted to 0xEFBFBD. This is the UTF-8 'replacement character'.
My request has Accept set to application/zip and the response has Content-Type: application/zip.
My expectation is that the API Gateway should recognize this as a binary media type and leave the file alone, but it seems pretty clear that it's processing it as text content.
What am I doing wrong?
Setting the "Binary Media Type" to "multipart/form-data" resolved a similar issue for me. See here: AWS Api Gateway as a HTTP Proxy is currupting binary uploaded image files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With