Reputation: 71
I just set-up an API gateway (AWS) to return binary data (image/png). My API was read and decode base 64 successful from lambda, then return a binary data, but it can not display on my browser. This is my gateway log:
When I request from the postman, it cannot be displayed, and response is base64 data:
Can anyone help me for this case? Thank you!
Upvotes: 2
Views: 1673
Reputation: 6515
When you are getting an image from the browser, the browser will set the accept header to something like, Accept: image/webp,image/apng,image/*,*/*;q=0.8
, and API Gateway will only pick the first value from the Accepts header.
If the first value matches the pattern in the binaryMediaTypes, API Gateway will consider it as binary data so it will be converted from base64 String to binary data or pass through the binary data.
If you don't have the behavior changes based on the Accepts header from the client/browsers, you can always set the contentHandling property to CONVERT_TO_BINARY
on the integration response, then API Gateway will ignore the Accepts header.
I suggest that you can put image/*
to the binaryMediaTypes on the API, then re-deploy the API and try again on the browsers. It should be returned as binary data.
Upvotes: 2
Reputation: 1
The data you got from the api gateway is binary data. Try to write the output to a file and save it. That should be your image file.
I am doing the same use case, but I am failing in the api-gateway. Could you share the piece of your api-gateway code.
Upvotes: 0