title: Node JS How to POST image along with request data to another server/api
body: <p>I am trying to POST an image from my Node JS app to another REST API. I have the image in Mongo DB (as binary array data) that is read by Node JS and then is supposed to be POSTed to another API.</p>
  
  <p>The problem I face is how do I send request data along with the image? I have this raw data (that is in JSON format) that should be POSTed along with image:</p>
  
  <pre><code>{"data":{"client":"abc","address": "123"},"meta":{"owner": "yourself","host": "hostishere"}}
  </code></pre>
  
  <p>I am required to do this using the 'request' module. I can use 'multer' if that helps better. But, I am stuck on how do I send the above request data along with the image stream. Below is my current code. Could you please help me finish it?</p>
  
  <pre><code>        var options = {
              host: 'hostname.com',
              port: 80,
              path: '/api/content',
              method: 'POST',
              headers:{
                  'Content-Type' : 'multipart/form-data'
              }
          };
  
          var request =  http.request(options, function(response) {
              var str = '';
              var respTime ='';
  
              response.on('data', function (chunk) {
                  str = str.concat(chunk);
              });
              response.on('end', () =&gt; {
                  console.log('No more data in response.');
              });
  
              setTimeout(function() {
                  res.send(JSON.stringify(
                    {
                        'imageURL': IMG_URL,
                        'imageId': IMG_ID,
                        'body': JSON.parse(str)
                    }
                  ));
              }, 1000);
          });
  
          request.on('error', (e) =&gt; {
            console.error('**** problem with request: ', e);
          });
  
          request.write(image.IMG_STR); //image.IMG_STR is the binary array representation of the image.
          request.end();
  </code></pre>
  
  <hr>
  
  <p>UPDATE: 06/06/2017</p>
  
  <p>So, I happened to talk to the REST team that provides the end point and found out that the data should be sent in the following specific format. Below is a snapshot of the request that succeeded. Could someone help me with the Node code that I should use? I have tried form-data package but have been getting the same error:
  <a href="https://i.stack.imgur.com/jit8O.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/jit8O.jpg" alt="Postman Snapshot"></a></p>