title: Send file in memory to API from Node Express
body: <p>I've an API in Node and Express which is receiving a file from a the client (Postman in development) and I use multer to get the file in memory like this:</p>
  
  <pre><code>router.post('/api/v1/upload', contrl.upload, contrl.uploadFile);
  </code></pre>
  
  <p>and then in my controller:</p>
  
  <pre><code>exports upload = multer({ storage: multer.memoryStorage() }).single('file');
  </code></pre>
  
  <p>Now I can access the file with req.file.buffer, but then I want to send this same file to another API.
  I'm using <code>request-promise-native</code> so this would be something like this:</p>
  
  <pre><code>const rp = require('request-promise-native')
  
  exports.uploadFile = (req, res) =&gt; {
  
    const options = {
      method: 'POST',
      uri: `${uri}`,
      form: {
        file: req.file.buffer
      }
    }
  
    rp(options)
      .then(parsedBody =&gt; {
        return res.status(201).send(parsedBody);
      })
      .catch(err =&gt; res.status(400).send(err));
  }
  </code></pre>
  
  <p>I removed some other params for simplicity, but this is not working, probably because Node doesn´t know how to handle the info inside req.file.buffer.</p>
  
  <p><strong><em>EDIT.</em></strong> Ok after some tests I tried to make this work with a real file instead of using multer memoryStorage. So I got this:</p>
  
  <pre><code>exports upload = multer({ dest: 'uploads/' }).single('file');
  </code></pre>
  
  <p>to save the file to disk, and then</p>
  
  <pre><code>const request = require('request')
  
  exports.uploadFile = (req, res) =&gt; {
  
    const formData = {
      file: fs.createReadStream('uploads/' + req.file.filename)
    }
    const options = {
      url: `${uri}`
      formData
    }
  
    request.post(options, (err, response, body) =&gt; {
      if (err) return res.status(400).send(err);
      return res.status(201).send(response);
    });
  }
  </code></pre>
  
  <p><strong>And it works!</strong> But then when I change to memoryStorage in multer and I use <code>file: req.file.buffer</code> instead, it does not work.</p>
  
  <p><strong><em>EDIT2:</em></strong> I also tried to send the file as a stream when in memory, so I tried this</p>
  
  <pre><code>const bufferStream = new stream.PassThrough();
  bufferStream.end(req.file.buffer);
  </code></pre>
  
  <p>and then passing it in the formData with <code>file: bufferStream</code> but also not working.</p>
  
  <p>How can I achieve this?
  Thanks</p>