I have just read lots of forum messages and some stackoverflow messages. I tried everything. However, I could not send a PNG response through API Gateway. I use LAMBDA_PROXY in API Gateway.
In Lambda, I have a code like this:
exports.handler = (event, context, callback) => {
// some code here ...
image.encode("png",function(err, buffer) {
var generated = buffer.toString('base64');
var response = {
statusCode: 200,
headers:
{
"Content-Type": "image/png"
},
body: generated,
isBase64Encoded: true
};
callback(null, response);
});
}
Binary Media Types:
{
"apiKeySource": "HEADER",
"name": "testimage",
"createdDate": 1518592036,
"binaryMediaTypes": [
"image/png"
],
"endpointConfiguration": {
"types": [
"EDGE"
]
},
"id": "xxx"
}
Content Handling Type:
{
"statusCode": "200",
"contentHandling": "CONVERT_TO_BINARY",
"responseTemplates": {
"application/json": null
}
}
When I open the API Gateway URL on the browser I see image/png as content-type. but the response is encoded. so, browser can't interpret it. I see black screen.
I sent a CURL request like this: {code}curl -H "Accept: image/png" https://xxx.execute-api.eu-central-1.amazonaws.com/testimage/myimage > /opt/1.png{code}
This one doesn't work, either.
What is wrong? Can you help me?