Sending binary data (image)

Hello, I’m using aws/lambda with serverless and have an endpoint I’d like to render a gif. I’ve added ‘image/gif’ to Binary Support in API Gateway and have the following in my lambda handler

const response = {
    statusCode: 200,
    headers: {
      'Content-Type': 'image/gif'
    isBase64Encoded: true

This shows the correct content-type, but it doesn’t actually render the image. I’ve seen some posts here, that it’s not supported, then some that it is supported and there’s plugins. Seems like things are partially working for me here, but perhaps a setting in API gateway? Any suggestions would be great.

Apparently using this hex seems to work or at least render the image (1px)

 var imageHex = "\x42\x4d\x3c\x00\x00\x00\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00"+ 

I found this here:

Not quite sure why this would work but my base64 wouldn’t. I tried multiple variations of the base64 (excluding data:image/gif;base64, and only sending the base64 string, but none of that seemed to render in the browser.

I don’t have an exact answer but struggled with it myself, so some pointer:

  • Pls make sure it is “THAT” 1px that exact 1 px shown. To me, gateway shown 1px picture instead the picture from s3 which I wanted to show
  • YOLO check: don’t forget to “deploy” your API Gateway changes after you added the context type.

Once you done, consider using a plugin to keep your APIGateway configuration as part of serverless code.


Ask someone else why the hell there are two and how are they different :troll: