# Upload binary image file

**URL:** <https://forum.serverless.com/t/upload-binary-image-file/790>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [November 19, 2016, 8:27pm UTC](https://forum.serverless.com/t/upload-binary-image-file/790 "2016-11-19T20:27:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FedericoElles](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@FedericoElles](https://forum.serverless.com/u/FedericoElles)\
**Post date:** [November 19, 2016, 8:27pm UTC](https://forum.serverless.com/t/upload-binary-image-file/790/1 "2016-11-19T20:27:01Z")

</div>

I’m trying to upload a binary file directly to a lambda for storing in s3.  
It seems to work except the outcome has the same size but is not a readable png.  
Any idea which conversation is missing?

```
  //support binary files
  if (typeof event === 'string'){    
    params.Body = new Buffer(event, "binary");
    params.Key = 'binary/' + Math.round(Math.random()*1000000);
    if (event.substr(0,10).indexOf('PNG') > -1){
        params.Key += '.png';
    }
  }

```

Test via

`serverless invoke local --function hello --path bot.png -l true`

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [November 20, 2016, 11:04pm UTC](https://forum.serverless.com/t/upload-binary-image-file/790/2 "2016-11-20T23:04:59Z")

</div>

You need to make sure the object’s `ContentType` (aka. MIME type) is set correctly - the CLI tool will take care of this for you, but if you’re doing your upload with the SDK you will need to do it yourself.

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [November 21, 2016, 10:07am UTC](https://forum.serverless.com/t/upload-binary-image-file/790/3 "2016-11-21T10:07:50Z")

</div>

Have you thought about using direct upload to S3 instead of going via Lambda? See [http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html](http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html)

---

<div class="post-metadata">

**Author:** ![rcfrias](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rcfrias](https://forum.serverless.com/u/rcfrias)\
**Post date:** [August 22, 2017, 1:15am UTC](https://forum.serverless.com/t/upload-binary-image-file/790/4 "2017-08-22T01:15:50Z")

</div>

I tried that and hit the wall. AWS Docs are fuzzy and their example only works with text files. The most I came forward is to upload a corrupted image using this AWS S3 service proxy approach.
