AWS API Gateway Binary output without Accept header

主宰稳场 提交于 2019-12-12 08:09:26

问题


According to http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html

If contentHandling is not defined, and if the Content-Type header of the response and the Accept header of the original request match an entry of the binaryMediaTypes list, API Gateway passes through the body. This occurs when the Content-Type header and the Accept header are the same; otherwise, API Gateway converts the response body to the type specified in the Accept header.

I can't make the original request to send the Accept header. How can I make my AWS API Gateway to return in binary format? (image/jpeg). Because the image I'm sending back from s3 gets converted to text in the last stage (because the original request lacks of the Accept: image/jpeg header).


回答1:


Set the 'Content handling' in your integration response to 'Convert to binary'. When Convert to binary is set in the integration response, the Content-Type API Gateway response header is '*/*' so you need to create a header mapping in the integration response for Content-Type, mapped to integration.response.header.Content-Type. This will ensure that the API Gateway response includes the same Content-Type value the backend passed in it's response to API Gateway.

Just to be clear, here is a summary of the required settings.

Integration Response:

  • Content handling: Convert to binary
  • Header Mappings: Content-Type: integration.response.header.Content-Type

This eliminates the need for an Accept request header from your client.



来源:https://stackoverflow.com/questions/41037026/aws-api-gateway-binary-output-without-accept-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!