title: Node.js upload Image Stream.Readable to S3
body: <p>My lambda is triggered by a request from the browser. The browser sends an image as <code>multipart/form-data</code>.</p>
  <p>The lambda uses <code>busboy</code> to parse the request:</p>
  <pre class="lang-js prettyprint-override"><code>function parseForm(event: IHttpEvent) {
    return new Promise(
      (resolve, reject) =&gt; {
        const busboy = new Busboy({
          headers: event.headers,
          limits: { files: 10 },
        });
        const imageResponse = new Map&lt;string, IImageParseResponse&gt;();
  
        busboy.on(&quot;file&quot;, (id, file, filename, encoding, mimeType) =&gt; {
             imageResponse.set(id, { file, filename, mimeType });
        });
  
        busboy.on(&quot;error&quot;, (error) =&gt; reject(`Parse error: ${error}`));
        busboy.on(&quot;finish&quot;, () =&gt; resolve(imageResponse));
  
        busboy.write(event.body, event.isBase64Encoded ? &quot;base64&quot; : &quot;binary&quot;);
        busboy.end();
      }
    );
  }
  </code></pre>
  <p>When I parsed the request I want to upload the file to AWS S3.</p>
  <pre class="lang-js prettyprint-override"><code>export async function handler(event: IHttpEvent) {
    var res = await parseForm(event);
    const s3 = new S3Client({ region: &quot;eu-central-1&quot; });
    for (const [k, v] of res) {
      console.log(`File ${v.filename} ${v.mimeType} streaming`);
      const stream = new Readable().wrap(v.file);
      const upload = new Upload({
        client: s3,
        params: {
          Key: v.filename,
          Bucket: &quot;my-image-bucket&quot;,
          Body: stream,
          ContentType: v.mimeType,
        },
      });
      upload.on(&quot;httpUploadProgress&quot;, (p) =&gt; console.log(p));
      const result = await upload.done();
      console.log(result);
      return result;
    }
  }
  </code></pre>
  <p>This does not work. However the Browser will receive a <code>200 OK</code> with a <code>null</code> body response. What confuses me even more is that <code>console.log(result);</code> does not log anything to console.</p>
  <p>Where is my mistake? I dont't fully understand the mechanics of streams. But as far as I understand it will be more memory-efficient. In the future I plan to upload multiple images at once. And in order to save cost I want my method to be as efficient as possible.</p>