title: multipart File uploads using NodeJS
body: <p>I am having troubles getting file uploads to work with NodeJS.  I am using Dropzone.JS to create a form that sends a POST request to /file-upload here:</p>
  
  <pre><code>&lt;form action="/file-upload" class="dropzone dragndrop" id="my-awesome-dropzone"&gt;&lt;/form&gt; 
  </code></pre>
  
  <p>Then I have a route in app.js:</p>
  
  <pre><code>app.post('/file-upload', routes.upload);
  </code></pre>
  
  <p>Then my handler:</p>
  
  <pre><code>exports.upload = function(req, res){
       console.log(req.files);
       res.send("OK");
  }
  </code></pre>
  
  <p>However, the upload function here is never called. The server crashes with this error first:</p>
  
  <pre><code>events.js:69
          throw arguments[1]; // Unhandled 'error' event
                         ^
  Error: Invalid data
      at WriteStream._write (fs.js:1616:31)
      at onwrite (_stream_writable.js:265:14)
      at WritableState.onwrite (_stream_writable.js:94:5)
      at fs.js:1628:5
      at Object.wrapper [as oncomplete] (fs.js:475:5)
      at process._makeCallback (node.js:321:24)
  </code></pre>
  
  <p>So I am not sure what I should do because it appears that this is not my fault. I followed other tutorials and saw nothing wrong. Also, when I inspect my Network under chrome dev tools, it shows:</p>
  
  <pre><code>Request URL:http://localhost:3000/file-upload
  **Request Headers**
  Accept:application/json
  Cache-Control:no-cache
  Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryMmLSkbfQskfIcjfE
  Origin:http://localhost:3000
  Pragma:no-cache
  Referer:http://localhost:3000/
  User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
  X-File-Name:Screenshot from 2013-03-20 12:23:42.png
  X-Requested-With:XMLHttpRequest
  **Request Payload**
  ------WebKitFormBoundaryMmLSkbfQskfIcjfE
  Content-Disposition: form-data; name="file"; filename="Screenshot from 2013-03-20 12:23:42.png"
  Content-Type: image/png
  
  
  ------WebKitFormBoundaryMmLSkbfQskfIcjfE--
  </code></pre>