title: Streaming an octet stream from request to S3 with knox on node.js
body: <p>I'm trying to stream an octet-stream straight to S3 using <a href="https://github.com/LearnBoost/knox/" rel="nofollow">knox</a> on node.js. The octet-stream is an XHR file upload from the browser. I assumed that I could just stream the request into putStream and everything would just work, but alas no.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>var client = knox.createClient({ 
             // AWS credentials here
           });
  if (req.headers['content-type'].match(/application\/octet-stream/i)) {
  
    var filename = '/'+req.headers['x-file-name'];
  
    client.putStream(req, filename, function(err, res){
      // TODO: Catch errors
      body = '{"success":"true"}'
      res.writeHead(200, 
        { 'Content-Type':'text/html'
        , 'Content-Length':body.length
        })
      res.end(body)
    });
  
  }
  </code></pre>
  
  <p>And the error I receive:</p>
  
  <pre><code>TypeError: Bad argument
      at Object.stat (fs.js:354:11)
      at Client.putStream (./lib/knox/client.js:181:6)
  </code></pre>