title: How can I forward a mulitpart file stream from fastify-multipart to a 3rd part api?
body: <p>I have a node api that I'm building that's capable of handling uploads of multipart file types (chunks). This api is based on the Fastify library, and I've already installed the separate Fastify-Multipart library. I've got everything working, including mulitpart file uploads, but part of the requirements of this api is to be able to send requests to another api. In particular, I need to send the file uploads. I don't know what their api is written in, but their multipart file upload api is basically like this:</p>
  
  <pre><code>sdk.files.uploader(location_id, file_size, "filename.jpg", file)
  .then(uploader =&gt; uploader.start())
  .then(file =&gt; { console.log(file) })
  </code></pre>
  
  <p>My code is basically this:</p>
  
  <pre><code>post: async (request, reply) =&gt; {
  
          // Check for file upload
          if((request.headers['content-type'] &amp;&amp; request.headers['content-type'].indexOf('multipart/form-data') !== -1) &amp;&amp; request.params.id) {
  
              const multipart = request.multipart(async (field, stream, filename, encoding, mimetype) =&gt; {
  
                  console.log(`folderId: ${request.params.id} filename: ${filename}, 
                              field name: ${field}, encoding: ${encoding}, 
                              mime type: ${mimetype}, file length: ${request.headers['content-length']}`)
  
                  try {
                      let uploader = await sdk.files.uploader(request.params.id, Number(request.headers['content-length']), filename, stream)
                      let file = await uploader.start()
                      console.log(file) //Never reaches this point
                  }
                  catch(e) {
                      console.log(`An error occurred during upload: ${e.message}`)
                      reply.code(500).send()
                  }
                  //pump(file, fs.createWriteStream(filename))
  
              }, (error) =&gt; {
  
                  if(error) {
                      console.log(`Error uploading file: ${error.message}`)
                      reply.code(500).send()
                  } else {
                      console.log('File upload succeeded') //Upload succeeds but it's just in memory
                      reply.code(201).send()
                  }
              })
  
              multipart.on('field', (key, value) =&gt; {
                  console.log('form-data', key, value)
              })
          }
      }
  </code></pre>
  
  <p>So basically what I want to do is pass a multipart file stream to this 3rd party api, but doing it this way doesn't seem to be working (when I go on their site, I don't see the file in the folder where it should be). When I look at Activity Monitor on my machine (macOS), I see the node process is consuming 1.2 Gig of memory (roughly the size of the file). Does anyone know a way to do this using Fastify-Multipart (which I believe is based on BusBoy).</p>