title: Sending a buffer in multipart/form-data POST request Node | Express | request
body: <p>I have a buffer that I have taken from users uploaded image, that I then want to send on to another API in a multipart/form-data POST request.</p>
  
  <p>I'm having issues however with the request object. I want to send a stream or buffer rather than accessing local server file system / creating temp files. I'm fairly new to the concept of streams.</p>
  
  <p>I get the correct response from API sending<br>
   <code>image_file: fs.createReadStream('image.png')</code></p>
  
  <p>But when I try:<br>
  <code>image_file: data // buffer</code></p>
  
  <p>I get an error from the API saying I'm missing the <code>image_file</code> parameter.</p>
  
  <p>Please help!</p>
  
  <p><a href="https://console.faceplusplus.com/documents/5679127" rel="noreferrer">Docs</a> for the API I'm using (Face++)<br>
  I'm using <a href="https://www.npmjs.com/package/request#forms" rel="noreferrer">request</a> to make the post request.</p>
  
  <p>Here is my code in question:</p>
  
  <pre><code>app.post('/', (req, res) =&gt; {
  
      const url = 'https://api-us.faceplusplus.com/facepp/v3/detect';
  
      let data = [];
  
      req.on('data', (chunk) =&gt; {
          data.push(chunk)
      })
  
      req.on('end', (req, res) =&gt; {
  
          data = Buffer.concat(data);
  
          const formData = {
              api_key: process.env.FACEPP_API_KEY,
              api_secret: process.env.FACEPP_API_SECRET,
              // image_file: fs.createReadStream('image.png') // works
              image_file: data // doesnt work
          }
  
          const options = {
              uri: url,
              method: 'POST',
              formData
          }
  
          request(options, (err, response, body) =&gt; {
              if (err) console.log(err)
              console.log(body)
          })
      })
  })
  </code></pre>