Enabling binary support using the API Gateway
Last month, I was working on gamification microservice APIs. We needed a feature to upload files and store them in the S3 bucket. The gamification microservice API was running in the lambda function. Everything was working fine but the upload feature was not working. I research a bit and found that the binary support should be enabled in AWS API Gateway. As soon as I enabled the binary support in AWS API Gateway, the upload feature worked smoothly.
To upload files or enable binary support by using the API Gateway console
- Select your API
- Go to Settings
- Scroll and find Binary Media Types
- Choose Add Binary Media Type
- Type a required media type, for example, image/png, in the input text field. If needed, repeat this step to add more media types. To support all binary media types, type */*, or you simply can add multipart/form-data and save
- Go to Resources
- Click proxy method (eg. ANY)
- Click Method Request and then HTTP Request Headers
- Add the following headers "Content-Type" and "Accept".
Finally, deploy your API.