- Newest
- Most votes
- Most comments
I solved it myself. According to http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html: If content handling 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 binary media types 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.
But if I want to get the image through a URL, I cannot affect the Accept header (this is what Postman did different and why it worked there). So the solution was to define a content handling and then to map response header Content-Type:
Integration Response:
- Content handling: Convert to binary
- Header Mappings: Content-Type: integration.response.header.Content-Type
When "Convert to binary" is set in the integration response, the API Gateway response header Content-Type is '*/*' at first. That's why we have to add the header mapping as well: this will ensure that the API Gateway response includes the same Content-Type the backend passed in it's response to API Gateway.
That was it, now the image is returned properly so that my browser can display with a simple URL call.
Hi,
Yes, you seem to fetch the image properly. So, did you check the config of your browser re. image extensions, ad blocking, etc.
I'd suggest to verify by following guidance of this article: https://www.computerhope.com/issues/ch000813.htm ?
Best,
Didier
Hello and thank you for your answer. I do not think the browser is the issue, because it can display images, and also the image in question when I open it directly from S3 in AWS console as shown in my first screenshot. This is from the browser and image is loaded correctly. It only does not work if I access the image through the API GET link instead. To me that tells me something isn't fully returned with the API. Also please consider the last part I added in my question: when I changed response integration to 'image/*' and the file was downloaded instead (not displayed in browser), the file was faulty and not open-able in on Windows PC.
Relevant content
- Accepted Answerasked 10 months ago
- Accepted Answerasked a month ago
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
Thank you so much. this was kicking my A** for an entire day