IE 11: Error sending data request Multipart Form: stream terminated unexpectedly

I am trying to upload files along with some other form fields using jQuery AJAX calls.

This is a normal function that calls the URL on the server:

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); }); } 

When checking with dev tools from browsers, this is the content of the request:

From IE11

 -----------------------------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 <Binary File Data Not Shown> ---------------------------7dfad39402e6 

Chrome

 ------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-- 

On the server side, we process the request as:

 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); } 

This code works fine with Chrome and Firefox, but when you try IE11 throws the following exception.

 javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: org.apache.commons.fileupload.FileUploadException: Stream ended unexpectedly 

I referred to these SO questions, but in vain.

Any useful pointers are welcome. Thanks.

+6
source share
2 answers

A strange problem came out. This is how it was resolved.

  • We had flags at the end of the form. The indicated problem arose when we did not select any of these flags. The request did not form correctly, and therefore, the server refused an error.
  • A hidden field has been added at the end of the form (make sure that this is the last form field) and assigned a value.

That's all. Worked like magic!

More details here .

+9
source

I had the same problem. I had only the id attribute and there was no name attribute in the hidden input field, which gave me the error below. The problem was resolved after adding the name attribute to the input field of the hidden type.

id = "timestamp" name = "timestamp"

Called: org.apache.commons.fileupload.MultipartStream $ MalformedStreamException: thread terminated unexpectedly Called: org.apache.commons.fileupload.FileUploadException: thread terminated unexpectedly

+1
source

Source: https://habr.com/ru/post/980871/


All Articles