title: How to upload a JPG on to AWS Lambda (NodeJS)
body: <p>I am trying to do this:</p>
  
  <ol>
  <li>Frontend: set up file to upload using <code>&lt;input type="file"&gt;</code> and <code>&lt;input type="button" onClick="..."&gt;</code></li>
  <li>The File Object is retrieved using <code>file[0]</code> from the <code>&lt;input type="file"&gt;</code>'s value.</li>
  <li>Use Javascript <code>Fetch</code> api to call on my AWS API-Gateway <code>Post</code> API.</li>
  </ol>
  
  <p><strong>I have tried both <code>multipart/form-data</code> and <code>application/json</code> in the request.</strong></p>
  
  <ol start="4">
  <li>On the AWS Lambda, I have used Buffer Object to consume the body.</li>
  </ol>
  
  <p><strong>I have tried using <code>Buffer(body, "utf8")</code>, <code>Buffer(body, "base64")</code>, <code>Buffer(body, "binary")</code>.</strong></p>
  
  <ol start="5">
  <li>This is, in turn, pushed up to <code>S3</code> for storage using <code>putObject</code>.</li>
  </ol>
  
  <p><strong>Problem:</strong></p>
  
  <ul>
  <li><p>The file object that was set up in <code>S3</code> has either filesize 0 or some random value that's not matching the original filesize.</p></li>
  <li><p>The file downloaded from <code>S3</code> cannot be opened.</p></li>
  </ul>
  
  <p><strong>Failed Approaches</strong></p>
  
  <p>I have considered <code>multer</code> and <code>multiparty</code>. These seem to be <code>ExpressJS</code> middleware and expects a <code>HttpRequest</code> object as input (this wasn't mentioned explicitly. It seems like I am ignorant enough not to assume that these can only work with <code>HttpRequest</code> object and it took me a while to find out). I am also ignorant enough not to know how to transform an AWS event object into a HttpRequest object. But that said, it seems excessive to use Express engine just for the sake of managing file upload.</p>
  
  <p>Exposing my <code>S3</code> bucket as <code>public-read-write</code> seems to be rather insecure. So I am not considering the frontend directly moving stuff in/out of my <code>S3</code> bucket. </p>
  
  <p><strong>My Request</strong></p>
  
  <p>Can anyone tell me how to get this to work? And/or an alternative to this approach?</p>