title: AWS lambda function issue with FormData file upload
body: <p>I have a nodejs code which uploads files to S3 bucket.
  I have used koa web framework and following are the dependencies:</p>
  
  <pre><code>    "@types/koa": "^2.0.48",
      "@types/koa-router": "^7.0.40",
      "koa": "^2.7.0",
      "koa-body": "^4.1.0",
      "koa-router": "^7.4.0",
  </code></pre>
  
  <p>following is my sample router code:</p>
  
  <pre><code>import Router from "koa-router";
  
  const router = new Router({ prefix: '/' })
  router.post('file/upload', upload)
  
  async function upload(ctx: any, next: any) {
      const files = ctx.request.files
      if(files &amp;&amp; files.file) {
        const extension = path.extname(files.file.name)
        const type = files.file.type
        const size = files.file.size
        console.log("file Size---------&gt;:: " + size);
        sendToS3();
      }
    }
  
  function sendToS3() {
     const params = {
        Bucket: bName,
        Key: kName,
        Body: imageBody,
        ACL: 'public-read',
        ContentType: fileType
      };
  
     s3.upload(params, function (error: any, data: any) {
        if (error) {
          console.log("error", error);
          return;
        }
        console.log('s3Response', data);
        return;
      });
  }
  </code></pre>
  
  <p>The request body is sent as FormData.</p>
  
  <p>Now when I run this code locally and hit the request, the file gets uploaded to my S3 bucket and can be viewed. 
  In Console the file size is displayed as follows:
  <a href="https://i.stack.imgur.com/NNdo1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NNdo1.jpg" alt="filesize----&gt;32212"></a>
  which is the correct actual size of the file.</p>
  
  <p>But when I deploy this code as lambda function and hit the request then I see that the file size has suddenly increased(cloudwatch log screenshot below). 
  <a href="https://i.stack.imgur.com/lX8mq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lX8mq.jpg" alt="filesize----&gt;51619"></a></p>
  
  <p>Still that file gets uploaded to S3 but the issue is when I open the file it show following error.
  <a href="https://i.stack.imgur.com/T2Mxb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T2Mxb.jpg" alt="enter image description here"></a></p>
  
  <p>I further tried to find whether this behaviour persisted on standalone instance on aws. But it did not. So the problem occurs only when the code is deployed as a serverless lambda function.</p>
  
  <p>I tried with postman as well as my own front end app. But the issue remains.</p>
  
  <p>I don't know whether I have overlooked any configuration when setting up the lambda function that handles such scenarios.</p>
  
  <p>This is an unprecedented issue I have encountered, and really would want to know if any one else encountered same before. Also I am not able to debug and find why the file size is increasing. I can only assume that when the file reaches the service, some kind of encoding/padding is being done on the file.</p>