Here is my code thus far - I'd like to just return the image buffer as raw data rather than having it toString to an array.
I set the content-type to image/jpeg in the integration response on a http 200 response, but it's a broken image because I think it's a toString of the buffer rather than the raw data.
exports.handler = function(event, context) {
var srcKey = event.key || 'e_1.png';
var max_size = event.size || 100;
// Download the image from S3
s3.getObject({
Bucket: srcBucket,
Key: srcKey
}, function (err, response) {
if (err)
return context.fail('unable to download image ' + err);
var original = gm(response.Body);
original.size(function (err, size) {
if (err)
return context.fail('unable to download image ' + err);
resize_photo(size, max_size, original, function (err, photo) {
//res.setHeader('Content-Type', 'image/jpeg');
context.succeed(photo);
});
});
});
};