title: Passing a file via POST to NodeJS and then pass to another API without saving on Disk
body: <p>I need to receive a file from the user in a React UI (using axios), send this file to a NodeJS method via POST using Express and then, I need to send this same file via POST directly to another API (.NET WebAPI) without saving on disk. I'm trying to pass the data file directly (req.files.file.data), but the .NET API doesn't recognise the file in the request.</p>
  
  <p>Is there any possibility to create a temporary file within a "var" and send it as I do when I read a file from disk?</p>
  
  <p><strong>This example works fine with local files:</strong></p>
  
  <pre><code>var formData = {
    form: "{ abn: '666666666' }",
    files: JSON.stringify([
      { 
        name: "file1", 
        type: "1", 
        number: "6666" 
      },
      { 
        name: "file2",
        type: "3", 
        number: "3333" 
      },
    ]),
    // Pass multiple values /w an Array
    attachments: [
      fs.createReadStream(__dirname + '/../file1.txt'),
      fs.createReadStream(__dirname + '/../file2.txt')
     ],
  };
  var reqs = request.post({url:'https://tms-dev-api.micway.com.au/api/company/file', formData: formData, json: true}, function optionalCallback(err, response, body) {
    if (err) {
      return res.send(err);
    }
    return res.send({
      status: response.statusCode,
      body: body
    });
  });
  </code></pre>
  
  <p>I am creating a local file and then sending it through; however, I don't believe that it is the best way to do it. Like This:</p>
  
  <pre><code>router.post('/file', function(req, res) {
    var fstream;
    req.pipe(req.busboy);
    req.busboy.on('file', function (fieldname, file, filename) {
      fstream = fs.createWriteStream(__dirname + '/' + filename);
      file.pipe(fstream);
  
      var formData = {
      attachments: [
          fs.createReadStream(__dirname + '/' + filename)
        ],
      };
      var reqs = request.post({url:'https://tms-dev-api.micway.com.au/api/company/file', formData: formData, json: true}, function optionalCallback(err, response, body) {
        if (err) {
          return res.send(err);
        }
  
        console.log({
          status: response.statusCode,
          body: body
        })
  
        return res.send({
          status: response.statusCode,
          body: body
        });
      });
    });
  });
  </code></pre>
  
  <p>Thanks!</p>