4

I created an ASP.NET Core app using a project template in AWS Toolkit. I deployed it as AWS Lambda and noticed the binary files are being base64 encoded in the responses. I added the proper media types in the AWS API Gateway as shown below. The browser is sending the proper Accept settings. The response is showing x-amzn-remapped-content-length of 3346 which is the actual file size and the response size is 4464 which is the base64 encoded version.

I have seen responses about setting "contentHandling": "CONVERT_TO_BINARY" in yml files. I am not using any yml files. The project template already is setup with using a CloudFormation template (serverless.template). I tried putting the setting in there but it errors out. Either the template doesn't understand the setting during deployment or I was putting it in the wrong place in the template file.

Any ideas on how I can get the endpoint to send binary files as is without encoding?

enter image description here

enter image description here

enter image description here

Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374

1 Answers1

0

In serverless YML file in your endpoint in "x-amazon-apigateway-integration" object set "contentHandling" to "CONVERT_TO_BINARY". Check this Content Type Conversions in API Gateway

  • I am not using any yaml files as I mentioned. I am using serverless.template which is a CloudFormation template. It's not clear where to put it in this template. I also have set in the convert_to_binary in the response integration in AWS Console. – Tony_Henrich Dec 12 '19 at 19:03
  • @Tony_Henrich did you solve the problem? can you please share the solution? I got the same problem. thanks – wapt49 Mar 21 '21 at 21:55