title: iOS 6 (iPhone/iPad) Image Upload "Request Body Stream Exhausted" with NTLM/Windows Authentication
body: <p>I am working on trying to get iOS 6 to use XMLHttpRequest POSTs to upload images.  This works on desktop and Android web browsers, but with iOS 6 I am getting an error on the page being posted to: "Request Body Stream Exhausted". (Using iOS Simulator with the Safari Web Inspector).</p>
  
  <p>Here is the basic code of the page:</p>
  
  <pre><code>function fileSelected() {
      var file = document.getElementById('fileToUpload').files[0];
      if (file) {
          var fileSize = 0;
          if (file.size &gt; 1024 * 1024)
              fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
          else
              fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
          document.getElementById('fileName').innerHTML = 'Name: ' + file.name;
          document.getElementById('fileSize').innerHTML = 'Size: ' + fileSize;
          document.getElementById('fileType').innerHTML = 'Type: ' + file.type;
      }
  }
  function uploadFile() {
      var fd = new FormData();
      fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
      var xhr = new XMLHttpRequest();
      xhr.upload.addEventListener("progress", uploadProgress, false);
      xhr.addEventListener("load", uploadComplete, false);
      xhr.addEventListener("error", uploadFailed, false);
      xhr.addEventListener("abort", uploadCanceled, false);
      xhr.open("POST", "/UploadHandler.ashx");
      xhr.send(fd);
  }
  function uploadProgress(evt) {
      if (evt.lengthComputable) {
          var percentComplete = Math.round(evt.loaded * 100 / evt.total);
          document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
          document.getElementById('prog').value = percentComplete;
      }
      else {
          document.getElementById('progressNumber').innerHTML = 'unable to compute';
      }
  }
  function uploadComplete(evt) {
      /* This event is raised when the server send back a response */
      alert(evt.target.responseText);
  }
  function uploadFailed(evt) {
      alert("There was an error attempting to upload the file.");
  }
  function uploadCanceled(evt) {
      alert("The upload has been canceled by the user or the browser dropped the connection.");
  }
  </code></pre>
  
  <p>When doing this on any other browser, the handler returns correctly and uploads the file.  However, with iOS the ashx page has the error "request body stream exhausted". </p>
  
  <p>Here is a screenshot of the inspector:</p>
  
  <p><img src="https://i.stack.imgur.com/U5bvx.jpg" alt="Request Body Stream Exhausted"></p>
  
  <p>Any ideas?</p>
  
  <p><strong>UPDATE:</strong> This issue only occurs when NTLM/Windows authentication is enabled for the application in IIS.  With forms or anonymous authentication, the upload works fine.</p>
  
  <p>Thanks,</p>
  
  <p>John</p>