bootstrap
bootstrap copied to clipboard
IE will submit a blank parameter when using File Upload
So this quirk of IE that managed to prevent all file uploads from working in our system. The file upload widget uses a hidden field in the background. After selecting a file using the File Upload, the js will set the name attribute on this hidden field to a blank value. Looking as below:
<input type="hidden" name="" value="">
The problem with this is that in IE (<=11), this input field will actually get passed back:
Content-Type: multipart/form-data; boundary=---------------------------7de90b221bf8
{snip}
-----------------------------7de90b221bf8
Content-Disposition: form-data; name="UploadType"
Single
-----------------------------7de90b221bf8
Content-Disposition: form-data; name=""
-----------------------------7de90b221bf8
Content-Disposition: form-data; name="UploadFile"; filename="test.csv"
Content-Type: application/vnd.ms-excel
1,2,3,a,b,c
-----------------------------7de90b221bf8--
I don't know about other server-side languages, but when .Net MVC(5) receives this it will then fail to modelbind other data in the form. In my case, this meant that the UploadFile
was mapped correctly but the UploadType
didn't bind.
Suggested fix:
Replace instances of .attr('name', '')
with .removeAttr('name')
. In all browsers i have tested so far this will resolve the issue.
Confirm that issue also for Chrome and Firefox. Before selecting file:
<input type="hidden" name="RegistryDocument[file]" value="">
<input type="file" id="registrydocument-file" name="RegistryDocument[file]">
After selecting file:
<input type="hidden" name="" value="">
<input type="file" id="registrydocument-file" name="RegistryDocument[file]">
Name will be blank in all browsers, but only IE will send the blank input back on post
Blank name
attribute after selecting file is unwanted behavior at all.
@Minstel Please check if this is still done. If so
Replace instances of .
attr('name', '')
with.removeAttr('name')
. In all browsers i have tested so far this will resolve the issue.