# Sending binary data (image)

**URL:** <https://forum.serverless.com/t/sending-binary-data-image/2515>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [August 17, 2017, 2:28am UTC](https://forum.serverless.com/t/sending-binary-data-image/2515 "2017-08-17T02:28:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![webchaz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@webchaz](https://forum.serverless.com/u/webchaz)\
**Post date:** [August 17, 2017, 2:28am UTC](https://forum.serverless.com/t/sending-binary-data-image/2515/1 "2017-08-17T02:28:51Z")

</div>

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

```auto
const response = {
    statusCode: 200,
    headers: {
      'Content-Type': 'image/gif'
    },
    body: new Buffer("data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7", 'binary').toString('base64'),
    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.

---

<div class="post-metadata">

**Author:** ![webchaz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@webchaz](https://forum.serverless.com/u/webchaz)\
**Post date:** [August 17, 2017, 3:09am UTC](https://forum.serverless.com/t/sending-binary-data-image/2515/2 "2017-08-17T03:09:13Z")

</div>

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

```auto
 var imageHex = "\x42\x4d\x3c\x00\x00\x00\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00"+ 
  "\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x18\x00\x00\x00"+ 
  "\x00\x00\x06\x00\x00\x00\x27\x00\x00\x00\x27\x00\x00\x00\x00\x00"+
  "\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00"; 

```

I found this here: [https://chrislarson.me/blog/tutorial/2016/12/16/1x1\_pixel\_aws\_lambda.html](https://chrislarson.me/blog/tutorial/2016/12/16/1x1_pixel_aws_lambda.html)

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.

---

<div class="post-metadata">

**Author:** ![dzimine](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dzimine/32/1424_2.png) [@dzimine](https://forum.serverless.com/u/dzimine)\
**Post date:** [August 19, 2017, 12:38am UTC](https://forum.serverless.com/t/sending-binary-data-image/2515/3 "2017-08-19T00:38:47Z")

</div>

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.

> **[maciejtreder/serverless-apigw-binary](https://github.com/maciejtreder/serverless-apigw-binary)**
>
> serverless-apigw-binary - Serverless plugin for binary files support in AWS Gateway

  
or [https://github.com/ryanmurakami/serverless-apigwy-binary](https://github.com/ryanmurakami/serverless-apigwy-binary)

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