title: Streaming an uploaded file to an HTTP request
body: <p>My goal is to accept an uploaded file and stream it to <a href="http://wistia.com/" rel="nofollow">Wistia</a> using the <a href="http://wistia.com/doc/upload-api" rel="nofollow">the Wistia Upload API</a>. I need to be able to add fields to the HTTP request, and I don't want the file to touch the disk. I'm using <a href="https://nodejs.org/" rel="nofollow">Node</a>, <a href="http://expressjs.com/" rel="nofollow">Express</a>, <a href="https://github.com/request/request" rel="nofollow">Request</a>, and <a href="https://github.com/mscdex/busboy" rel="nofollow">Busboy</a>.</p>
  
  <p>The code below has two <code>console.log</code> statements. The first returns <code>[Error: not implemented]</code> and the second returns <code>[Error: form-data: not implemented]</code>. I'm new to streaming in Node, so I'm probably doing something fundamentally wrong. Any help would be much appreciated.</p>
  
  <pre><code>app.use("/upload", function(req, res, next) {
      var writeStream = new stream.Writable();
      writeStream.on("error", function(error) {
          console.log(error);
      });
      var busboy = new Busboy({headers: req.headers});
      busboy.on("file", function(fieldname, file, filename, encoding, mimetype) {
          file.on("data", function(data) {
              writeStream.write(data);
          });
          file.on("end", function() {
              request.post({
                  url: "https://upload.wistia.com",
                  formData: {
                      api_password: "abc123",
                      file: new stream.Readable(writeStream)
                  }
              }, function(error, response, body) {
                  console.log(error);
              });
          });
      });
      req.pipe(busboy);
  });
  </code></pre>