# Upload image to s3, image broken

**URL:** <https://forum.serverless.com/t/upload-image-to-s3-image-broken/12390>\
**Category:** Serverless Framework\
**Tags:** aws, api-gateway\
**Created:** [August 26, 2020, 10:32am UTC](https://forum.serverless.com/t/upload-image-to-s3-image-broken/12390 "2020-08-26T10:32:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nkhanhcong](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@nkhanhcong](https://forum.serverless.com/u/nkhanhcong)\
**Post date:** [August 26, 2020, 10:32am UTC](https://forum.serverless.com/t/upload-image-to-s3-image-broken/12390/1 "2020-08-26T10:32:58Z")

</div>

I upload image to s3 through lambda function.  
I used `sls offline start` to upload, everything is fine, I could see the image that I uploaded.  
But when I deploy it to aws and call api, my image was uploaded but couldn’t be seen. After I downloaded image, I also couldn’t open my picture because it was damaged.

Code uploaded:

const lstData = Promise.all(files.map(async file\_obj =\> {

```
let fileExtension = file_obj.filename.split('.').pop()
        const actionId = uuid.v4()
        let buf = new Buffer(file_obj.content, 'binary')
        // console.log(file_obj.content)
        const s3Params = {
            Bucket: process.env.AWS_BUCKET,
            Key: `${actionId}.${fileExtension}`,
            ACL: 'public-read',
            ContentType: `${file_obj.contentType}`,
            Body: buf
        }
        let data = await s3.upload(s3Params).promise()

        return data

```

}}

**Solution I tried:**

- add multipart/form-data in Api Gateway

---

<div class="post-metadata">

**Author:** ![mule88](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mule88](https://forum.serverless.com/u/mule88)\
**Post date:** [June 8, 2021, 11:15am UTC](https://forum.serverless.com/t/upload-image-to-s3-image-broken/12390/2 "2021-06-08T11:15:37Z")

</div>

adding the below worked for me:

```auto
provider:
  apiGateway:
    binaryMediaTypes:
      - 'image/png'
      - ‘image/jpeg’
      - 'multipart/form-data'

```

---

<div class="post-metadata">

**Author:** ![prabhat510](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/prabhat510/32/8111_2.png) [@prabhat510](https://forum.serverless.com/u/prabhat510)\
**Post date:** [October 22, 2024, 4:07pm UTC](https://forum.serverless.com/t/upload-image-to-s3-image-broken/12390/3 "2024-10-22T16:07:26Z")

</div>

Thanks @mule88 for the answer, I was facing this issue and this solved my problem 🙂
