IE 11: Error while sending Multipart Form Data request: Stream ended unexpectedly

前端 未结 4 1273
挽巷
挽巷 2021-02-08 14:05

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

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

functi         


        
4条回答
  •  我寻月下人不归
    2021-02-08 14:30

    The issue you have mentioned has troubled me for a long time. I finally have a solution to the issue. IE appends an empty name form data at the end of the formData request object which gets parsed at the server and hence the error occurs.

    Below was the form data request object which was sent before the fix:

    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="csrfToken"
    
    8394D82F5A776708F13CDC6D4B4DE1485C1EC05625E63B2E
    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="ACTION"
    
    DELETE_LOGO
    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="ORG_ID"
    
    1879048492
    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name=" 
    -----------------------------7e3195134f056c--
    

    In order to resolve the issue, added an extra hidden field at the end of the form element.

        
            
            
    
            

    The request body is now sent as below which is parsed successfully:

    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="csrfToken"
    
    8394D82F5A776708F13CDC6D4B4DE1485C1EC05625E63B2E
    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="ACTION"
    
    DELETE_LOGO
    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="ORG_ID"
    
    1879048492
    -----------------------------7e3195134f056c
    Content-Disposition: form-data; name="dummyIEField"
    
    
    -----------------------------7e3195134f056c--
    

    Hope this helps. Cheers !!

提交回复
热议问题