2

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);
            });
        });
    });

};
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460
  • I'm not providing an answer but here is a similar question: http://stackoverflow.com/questions/31615734/returning-images-through-aws-api-gateway – Erik Sjölund Oct 25 '15 at 08:39

1 Answers1

1

This doesn't seem like something Lambda with API Gateway was designed for. Binary output may not be supported given the state of it's pipeline. Try doing something else instead - store the image back to the S3 and send back a HTTP Redirect to new S3 URI. Let the client handle it instead of trying to make the API Gateway pipeline handle binary responses.

adamkonrad
  • 6,794
  • 1
  • 34
  • 41