title: Piping stream from busboy to request post
body: <p>I have <code>multipart/form-data</code> that I am posting to an express endpoint <code>/data/upload</code>, form markup below:</p>
  
  <pre><code>form(enctype="multipart/form-data", action="/data/upload", method="post")
    input(type="file", name="data")
  </code></pre>
  
  <p>I'm using <code>busboy</code> to read the file stream, which is working fine.  From there, I want to send the stream again as <code>multipart/form-data</code> to a second Java backend, using the <code>request</code> npm module.  JS client/Java server code below:</p>
  
  <pre><code>  req.busboy.on('file', function (fieldName, fileStream, fileName, encoding, mimeType) {
  
      var reqBody = {
        url: server.baseURL + 'api/data',
        headers: {
          'Connection': 'keep-alive',
          'Content-Type': 'multipart/form-data'
        },
        formData: {
          file: fileStream
        }
      };
  
      request.post(reqBody, function (err, r, body) {
        // Do rendering stuff, handle callback
      });
   });
  </code></pre>
  
  <p><strong>Java endpoint (api/data)</strong></p>
  
  <pre><code>@POST
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public void addData(FormDataMultiPart formDataMultiPart) {
    // Handle multipart data here      
  }
  </code></pre>
  
  <p>I don't think I'm sending the file correctly as <code>multipart/form-data</code> here... but I'm having a hard time figuring out how to essentially pipe the stream from <code>busboy</code> directly to <code>request</code> without reading/writing from a temp file on the client-side.  Any ideas?</p>
  
  <p><strong>Java stack trace:</strong></p>
  
  <pre><code>Apr 27, 2016 5:07:12 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 3 * Server has received a request on thread qtp1631904921-24
  3 &gt; POST http://localhost:8080/api/data
  3 &gt; Connection: keep-alive
  3 &gt; Content-Length: 199
  3 &gt; Content-Type: multipart/form-data; boundary=--------------------------331473417509479560313628
  3 &gt; Host: localhost:8080
  
  Apr 27, 2016 5:07:12 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 3 * Server responded with a response on thread qtp1631904921-24
  3 &lt; 400
  
  17:07:13.003 [qtp1631904921-24] WARN  org.eclipse.jetty.http.HttpParser parseNext - bad HTTP parsed: 400 No URI for HttpChannelOverHttp@425137da{r=1,c=false,a=IDLE,uri=null}
  </code></pre>
  
  <p><strong>Rahat's recommended change</strong>:</p>
  
  <pre><code> 31     var reqBody = {
   32       url: server.baseURL + 'data',
   33       headers: {
   34         'Connection': 'keep-alive',
   35         'Content-Type': 'multipart/form-data'
   36       }
   37     };
   38 
   39     req.pipe(req.busboy.pipe(request.post(reqBody)));
  </code></pre>
  
  <p><strong>Threw error:</strong></p>
  
  <pre><code>Error: Cannot pipe. Not readable.
     at Busboy.Writable.pipe (_stream_writable.js:154:22)
  </code></pre>