title: Send a file with XmlHttpRequest: Streaming?
body: <p>I am trying to upload big files with drag and drop. I have this piece of Javascript code:</p>
  
  <pre><code>xhr = new XMLHttpRequest();
  xhr.open('POST', url, true);
  xhr.setRequestHeader('X-File-Name', file.name);
  xhr.setRequestHeader('X-File-Size', file.size);
  xhr.setRequestHeader('Content-Type', file.type);
  xhr.send(file);
  </code></pre>
  
  <p>where <code>url</code> is a string of the target url and <code>file</code> is a <code>Blob</code> (according to <a href="http://www.w3.org/TR/XMLHttpRequest2/#the-send-method" rel="noreferrer">http://www.w3.org/TR/XMLHttpRequest2/#the-send-method</a>) which I have retrieved after a file drag-drop. This code works in Chrome 12, Safari 5 and Firefox 4 and sends the raw contents of the file in the body of the HTTP request.</p>
  
  <p>However, if the file is big enough the request is never sent. Instead, the <code>XMLHttpRequest</code> object fires and error event (without any useful message). This limit is 86Mb in my environment, but it varies from machine to machine. </p>
  
  <p>The javascript console of Chrome shows the message:</p>
  
  <pre><code>POST http://localhost/xfiles/xfiles.php undefined (undefined)
  </code></pre>
  
  <p>which has nothing to do with my code (which works perfectly with smaller files). </p>
  
  <p>It seems that the browser reads the entire file in memory and before sending it. Probably there is an out of memory exception or something like that that stops the process. In any case, there no HTTP request is sent, so it is certain that the server's limits have nothing to do with this problem.</p>
  
  <p>Anyway, <strong>reading the entire file is a waste of resources</strong>.</p>
  
  <p>Is there any method to send the file in a streaming fashion, byte by byte, without having to store it in the memory first?</p>