title: nodejs - request - express- use file readStream inside of a post handler
body: <p>I'm using nodejs and express4. I have a form - post method (file upload as base64) and I'm saving this file to a gridfs with streams. </p>
  
  <p>this is my code: </p>
  
  <pre><code>exports.transcribe = function (gridfs, req, res) {
  
      const buffer = Buffer.from(req.body.file.split(';base64,')[1], 'base64')
      let contentType = req.body.file.split(';base64,')[0].replace('data:', '')
      streamifier.createReadStream(buffer).pipe(gridfs.createWriteStream({
          filename: uuid.v4() + '.txt',
          content_type: contentType,
          metadata: {
              user: req.user
          }
      }))
      // this is request-promise-native
      request.post({
          headers: {
              'Content-Type': 'multipart/form-data'
          },
          uri: process.env.REST_ENDPOINT,
          // stream is created with streamifier from a buffer object
          formData: {'file': streamifier.createReadStream(buffer)}
      }).then(console.log).catch(console.error)
      res.status(200).json({file: file, user: req.user})
  }
  </code></pre>
  
  <p>the code works when execuded synchronous but it does not inside the request handling. </p>
  
  <p>I read about that maybe the stream is canceled before I am able to send it. 
  What is missing is the content of the file. The request itself is executed.</p>