title: IE 11: Error while sending Multipart Form Data request: Stream ended unexpectedly
body: <p>I am trying to upload files along with some other form fields using jQuery AJAX calls.</p>
  
  <p>This is a common function that calls the URL on the server:</p>
  
  <pre><code>function uploadDocument(rquestURL,formId,callback){
          $.ajax({
              type : 'POST',
              url : rquestURL,
              cache:false,
              processData:false,
              contentType:false,
              data : new FormData($("#"+formId)[0])
          }).done(function(response) {
              callback(response);
          });
  }
  </code></pre>
  
  <p>On examining from the dev tools from browsers, these are the respective request contents:</p>
  
  <p><strong>From IE11</strong></p>
  
  <pre><code>-----------------------------7dfad39402e6
  Content-Disposition: form-data; name="subject"
  
  Test
  -----------------------------7dfad39402e6
  Content-Disposition: form-data; name="message"
  
  Test test
  -----------------------------7dfad39402e6
  Content-Disposition: form-data; name="announcementAttachment"; filename=""
  Content-Type: application/octet-stream
  
  &lt;Binary File Data Not Shown&gt;
  ---------------------------7dfad39402e6
  </code></pre>
  
  <p><strong>Chrome</strong></p>
  
  <pre><code>------WebKitFormBoundaryp8rj3ArKDsbYw0BZ
  Content-Disposition: form-data; name="subject"
  
  Test
  ------WebKitFormBoundaryp8rj3ArKDsbYw0BZ
  Content-Disposition: form-data; name="message"
  
  Test test
  ------WebKitFormBoundaryp8rj3ArKDsbYw0BZ
  Content-Disposition: form-data; name="announcementAttachment"; filename=""
  Content-Type: application/octet-stream
  
  
  ------WebKitFormBoundaryp8rj3ArKDsbYw0BZ--
  </code></pre>
  
  <p>On server side, we are parsing the request as:</p>
  
  <pre><code>import org.apache.commons.fileupload.FileItemFactory;
  import org.apache.commons.fileupload.servlet.ServletFileUpload;
  
  final FileItemFactory factory = new DiskFileItemFactory();
  final ServletFileUpload fileUpload = new ServletFileUpload(factory);
  
  if (ServletFileUpload.isMultipartContent(request)) {
          // get the request content and iterate through
          items = fileUpload.parseRequest(request);
  }
  </code></pre>
  
  <p>The code works fine from Chrome and Firefox, but throws the below exception when I tried from IE11.</p>
  
  <pre><code>javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: org.apache.commons.fileupload.FileUploadException: Stream ended unexpectedly
  </code></pre>
  
  <p>I referred to these SO questions but in vain.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/20788517/java-formdata-in-ie-throwing-org-apache-commons-fileupload-multipartstreammal">Java - FormData in IE throwing org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly</a></li>
  <li><a href="https://stackoverflow.com/questions/21714527/grails-multipart-service-stream-ended-unexpectedly">Grails Multipart Service Stream ended unexpectedly</a></li>
  </ul>
  
  <p>Any useful pointers are appreciated. Thanks.</p>