title: Uploading image file to S3 using API gateway NodeJS
body: <p>I'm trying to upload an image file to S3 using API Gateway. So it's a POST method where the body takes the image file using <code>form-data</code>. I wrote the lambda in TypeScript with the help of <code>lambda-multipart-parser</code>. It works fine locally but when i deploy it in AWS, the file size changes a bit and it seems the original file was not really uploaded properly.</p>
  <p>my lambda code is</p>
  <pre><code>import * as parser from 'lambda-multipart-parser'
  import { s3Upload } from '../helper/common'
  
  export const test = async (event) =&gt; {
    console.log('starting------')
    console.log('EVENT', event)
    const result = await parser.parse(event)
    console.log(result.files)
    const file = result.files[0]
    console.log('FILE', file)
  
    const s3Params = {
      Bucket: process.env.AWS_BUCKET,
      Key: `${Date.now().toString()}-${file.filename}`,
      Body: file.content,
      ContentType: 'image/png',
      ACL: 'public-read',
    }
    console.log('S3 PARAMS', s3Params)
    const s3Content = await s3Upload(s3Params)
    console.log('S3 CONTENT', s3Content)
  }
  </code></pre>
  <p>where i'm just calling the <code>s3Upload</code> from <code>helper</code></p>
  <pre><code>import { S3 } from 'aws-sdk'
  
  export const s3Upload = async function (params) {
    let s3: S3
    if (process.env.IS_OFFLINE) {
      s3 = new S3({
        accessKeyId: process.env.AWS_ACCESS_KEY,
        secretAccessKey: process.env.AWS_SECRET_KEY,
      })
    }
    return new Promise((resolve) =&gt; {
      s3.upload(params, (err, data) =&gt; {
        if (err) {
          console.error(err)
          resolve(err)
        } else {
          resolve(data)
        }
      })
    })
  }
  </code></pre>
  <p>this looks like a problem of the node package itself but i'm not sure! what are the other working ways i can achieve this objective which is to upload an image file to S3 using API gateway written in typescript?</p>