title: Best way to handle file uploads from Backbone.js to Rails-based API through a proxy?
body: <p>We have a Backbone.js app that supports file uploads using plupload. The uploads are sent through a proxy (rack-reverse-proxy at the moment, but switching to straight nginx shortly) to a separate Rails app through an API.</p>
  
  <p>This API has been in use for quite some time and can handle uploads of hundreds of MB.  We don't think it is the problem.</p>
  
  <p>When uploads are performed through BB.js and the proxy, however, they can stop at different points, but mostly it's at the sub-1.5MB point.</p>
  
  <p>Of note is that attempts to upload multiple files less than 1MB each work fine in the same situations.  I can upload 100 1MB files, but I can't upload any files more than, say, 2MB.</p>
  
  <p>Some of the exceptions we get are from the BB.js app are:</p>
  
  <ul>
  <li>Uncaught SyntaxError: Unexpected end of input</li>
  <li>SyntaxError: JSON Parse error: Unexpected EOF</li>
  </ul>
  
  <p>What's the best way to approach this?  The main culprit seems to be a slower network connection (uploads to the server over fiber-based home network tend to complete, whereas uploads over the DSL-line at work tend to fail), but I can't imagine it's that cut and dry.</p>
  
  <p>Is it our proxy setup?  Will switching to nginx fix this?  What's the best way to set up nginx for this purpose?</p>
  
  <p>EDIT to answer Maurício's comment:</p>
  
  <p>Nothing is returned from the server.  Here are the headers as reported by WebKit Network Inspector (hostname changed):</p>
  
  <pre><code>Request URL:http://our.site.com/api/files
  Request Headersview source
  Content-Length:131661475
  Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryHwVBiFW8AIuh18Bt
  DNT:1
  Origin:http://our.site.com
  Referer:http://our.site.com/
  User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
  Request Payload
  ------WebKitFormBoundaryHwVBiFW8AIuh18Bt
  Content-Disposition: form-data; name="name"
  
  861-railsconf2012-using-backbone-js-with-rails-patterns-from-the-wild-large.mp4.mpg
  ------WebKitFormBoundaryHwVBiFW8AIuh18Bt
  Content-Disposition: form-data; name="file_entry[folder_id]"
  
  32984
  ------WebKitFormBoundaryHwVBiFW8AIuh18Bt
  Content-Disposition: form-data; name="file"; filename="861-railsconf2012-using-backbone-js-with-rails-patterns-from-the-wild-large.mp4.mpg"
  Content-Type: video/mpeg
  
  
  ------WebKitFormBoundaryHwVBiFW8AIuh18Bt--
  </code></pre>
  
  <p>After that, there is no response.  The inspector reports both the status and time as Pending. In this most recent case, the transfer size is 0B, though I know data was sent as I can monitor outgoing traffic hitting 900K/sec for maybe 10-15 seconds, and then dying back down to normal (1-2K/sec).</p>