title: Problem with HTML5 XHR FileUpload and ASP.Net
body: <p>I'm trying to upload a file using HTML5's XMLHttpRequest.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.open("POST", "receive.aspx", true);
  //xhr.setRequestHeader("Content-Type", "multipart/form-data");
  xhr.setRequestHeader("Content-Type", "application/octet-stream");
  xhr.send($("#fileobject").files[0]);
  </code></pre>
  
  <p>On the server side, I get <code>0</code> for the <code>Request.Files.Count</code>. However if I read the input stream I get the headers of the file as follows:</p>
  
  <pre><code>------WebKitFormBoundarylAWVSRo5qeSpsnzn Content-Disposition:
  form-data; name="fileToUpload"; filename="a.txt" Content-Type:
  application/octet-stream
  
  Testing
  
  ------WebKitFormBoundarylAWVSRo5qeSpsnzn--
  </code></pre>
  
  <p>The file uploaded contains only the word "Testing".</p>
  
  <p>Server code:</p>
  
  <pre><code>Stream inputStream = Request.InputStream;
  FileStream fileStream = new FileStream("c:\\test.txt", FileMode.OpenOrCreate);
  inputStream.CopyTo(fileStream); 
  fileStream.Close();
  </code></pre>
  
  <p>Is there anything I'm missing in my client Javascript which is not populating the Request.Files object on the server? Or is there any way to read just the file contents without the headers?</p>