title: How can I send file to api that use multer in node js?
body: <p>I want to send a file from a server to another server, using two apis, one that upload to the final server and one that read a form data and send it to an api that call the first api</p>
  
  <p><strong>Upload to final server</strong></p>
  
  <pre><code>var storage = multer.diskStorage({
      destination: function (req, file, cb) {
          mkdirp(configServer.dataDir+ "/tmp", function(err){
              console.log("err * : ", err)
              if(err)
                  res.json({success:false, error:err})
              cb(null, configServer.dataDir+ "/tmp/")
          })
      },
      filename: function (req, file, cb) {
          console.log("file**", file)
          cb(null, file.fieldname + '-' + Date.now())
      }
  })
  
  var upload = multer({ storage: storage }).single('file');
  
  exports.upload_in_server = function (req, res) {
  
      upload(req, res, function (err) {
  
           console.log("body : ", req.body)
           console.log("file : ", req.file)
  
          if (err instanceof multer.MulterError) {
              // A Multer error occurred when uploading.
              console.log("err 1 : ", err)
          } else if (err) {
              // An unknown error occurred when uploading.
              console.log("err 2 : ", err)
          }
  
           res.json({success: true})
  
      })
  
  }
  
  router.post("/myurl/uploadInServer",  UserController.upload_in_server);
  </code></pre>
  
  <p>In next, the api called to send the file to the final server</p>
  
  <pre><code>var storage2 = multer.diskStorage({
      destination: function (req, file, cb) {
          mkdirp(config.dataDir+ "/tmp", function(err){
              console.log("err * : ", err)
              if(err)
                  res.json({success:false, error:err})
              cb(null, config.dataDir+ "/tmp/")
          })
      },
      filename: function (req, file, cb) {
          console.log("file**", file)
          cb(null, file.fieldname + '-' + Date.now())
      }
  })
  
  var upload2 = multer({ storage: storage2 }).single('file');
  
  exports.user_coffre_fort_create_file2 = function (req, res) {
  
  var querystring = require('querystring');
  
      upload2(req, res, function (err) {
  
          if (err instanceof multer.MulterError) {
              // A Multer error occurred when uploading.
              console.log("err 1 : ", err)
          } else if (err) {
              // An unknown error occurred when uploading.
              console.log("err 2 : ", err)
          }
  
          var FormData = require('form-data');
  
          var form = new FormData();
  
          const encoded = req.file.toString('base64')
  
          form.append('file', encoded);
  
          form.append('Name', "Lagaf");
          form.append('Surname', "Vincent");
          form.append('birthdate', "13/01/1960");
  
          request({
              url: "/myurl/uploadInServer",
              method: 'POST',
              json: querystring.stringify(form),
              headers: {"Content-Type": "application/x-www-form-urlencoded", "Authorization": my_tokentoken}
              //
          }, function (err, stdout, body) {
              res.json({success:true})
          })
      })
  }
  </code></pre>
  
  <p>This is what I receive in server, the body is not correct, and the file is undefined</p>
  
  <pre><code>body :  { '"_overheadLength': '420',
    _valueLength: '37',
  
  
  writable: 'false',
    readable: 'true',
    dataSize: '0',
    maxDataSize: '2097152',
    pauseStreams: 'true',
    _released: 'false',
    _streams: 
     [ '----------------------------081543624686364985445462\r\nContent-Disposition: form-data; name="file"\r\n\r\n',
       '[object Object]',
       '',
       '----------------------------081543624686364985445462\r\nContent-Disposition: form-data; name="Name"\r\n\r\n',
       'Lagaf',
       '',
       '----------------------------081543624686364985445462\r\nContent-Disposition: form-data; name="Surname"\r\n\r\n',
       'Vincent',
       '',
       '----------------------------081543624686364985445462\r\nContent-Disposition: form-data; name="birthdate"\r\n\r\n',
       '13/01/1960',
       '' ],
    _currentStream: '',
    _boundary: '--------------------------081543624686364985445462"' }
  files :  undefined
  </code></pre>
  
  <p>How to have a correct body and 'req.file' that is not <code>undefined</code>.</p>