title: How to send file data in post request in node using request module?
body: <p><strong>Requirement</strong>:</p>
  
  <p>I need to make an api call with the file uploaded by the user.My server is node and I use <strong>request</strong> module for making api calls.
  Below is the code when user uploads a file and submits it.</p>
  
  <pre><code>if(queryData.sub == "upload"){
      var input = {};
      var formidable = require('formidable');
      var form = new formidable.IncomingForm();
      form.parse(request, function (err, fields, files) {
      var fs = require('fs');
      fs.readFile(files.filetoupload.path, function(err, data) {
  
  
      input.x_file_content = data;
  
  
      client.API.ATTACHMENTS.uploadFile(input).then(function(resp){
  
          var str = settings.layoutParsing(resp);
              response.write(str);
              response.end();
      })
  
      });
  
      });
  }
  }
  </code></pre>
  
  <p>In upload file function i use FormData to set the file and send it while making api call .Below is the code:</p>
  
  <pre><code>if (request.x_file_content) {
  
              var FormData = require('form-data');
              var formData = new FormData();
              formData.append('file', request.x_file_content);//No I18N
              req_body = formData;
  
          }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>var httpclient = require('request');
  
  httpclient({
  
          uri : baseUrl,
          method : request.type,
          headers : api_headers,
          responseType : responseType,
          body : req_body
  
      },function(error,response,body){
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>but the file was not successfully sent and multipart content required error is thrown by the api server.</p>
  
  <p>Can anyone point out what mistake Im doing.</p>
  
  <p><strong>Thanks</strong> !</p>