title: Upload file to another server with request or axios nodejs
body: <p>I have a user form where a user can pick a file on their system and upload it to another server using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects" rel="nofollow noreferrer">FormData</a>. It works fine when testing sending it directly to the api. But I need to modify the headers before sending it. So I'm posting to the backend of the client app. </p>
  
  <pre><code>router.post('/upload', function(req, res, next) {
    //...some axios or request logic
  
    var fs = require('fs');
    var request = require('request');
    var formData = {
      my_field: 'my_value',
      my_file: fs.createReadStream(__dirname + '/example.doc'),
    };
  
    request.post({url:'http://someothereapp/upload-file', formData: formData}, function(err, httpResponse, body) {
      if (err) {
        return console.error('upload failed:', err);
      }
      console.log('Upload successful!  Server responded with:', body);
      res.send('good!');
    });
  
  });
  </code></pre>
  
  <p><code>axios</code> or <code>request</code> works great for posting normal forms or get request. But when I try to use it to send a file it doesn't work. The above code always returns success but does not upload the file. So i went <a href="https://stackoverflow.com/questions/25344879/uploading-file-using-post-request-in-node-js">here</a> and still don't understand enough to see what I am missing.</p>
  
  <p>I have authentication and tracking turned off on the other server (local) while testing so i don't have to modify headers. It has the following code that works fine if I send the file directly to it from the web form, but not from my client express app:</p>
  
  <pre><code>  // http://someothereapp/upload-file
    router.post('/upload-file', (req, res, next) =&gt; {
      let multer = require('multer')
      let p =  path.join(__dirname, '../uploads');
      let storage = multer.diskStorage({
        destination: function(req, file, callback) {
          callback(null, p )
        },
        filename: function(req, file, callback) {
          console.log('what is file', file)
          callback(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname))
        }
      })
  
      let upload = multer({
        storage: storage
      }).single('userFile')
      upload(req, res, function(err) {
        res.end('File is uploaded')
      })
    });
  </code></pre>
  
  <p>I saw <a href="https://github.com/mzabriskie/axios/issues/789" rel="nofollow noreferrer">this</a> issue and think it might mean its not possible with axios but how do you do it with request? For example, in the <code>post ... upload</code> code, how do i get <code>my_file</code> to be the file the user selected in their form? Why is it not failing even though it's not uploading a file?</p>