1 min readJul 25, 2018
AWS api gateway return binary image
in this article, just setup to response binary image via lambda :
- lambda response: {headers: { ‘Content-Type’: ‘image/png’}, isBase64Encoded: true}
- API Gateway: Setting Binary Media Type */* and lambda response
Lambda
just return base64 image string
exports.handler = async (event) => {
let result = "data:image/png;base64,....".replace(/data:image\/png;base64,/, '');
return {
statusCode: 200,
headers: {
'Content-Type': 'image/png'
},
body: result,
isBase64Encoded: true
}
}
API Gateway
api right Setting add Binary Media Types
:)
ref:
(not use Binary Media Type) https://sanderknape.com/2017/02/dynamic-image-generation-with-aws-api-gateway-and-lambda/