bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

IE will submit a blank parameter when using File Upload

Open elexisvenator opened this issue 10 years ago • 4 comments

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.

elexisvenator avatar Oct 29 '14 05:10 elexisvenator

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

creocoder avatar Dec 18 '14 08:12 creocoder

Name will be blank in all browsers, but only IE will send the blank input back on post

elexisvenator avatar Dec 18 '14 08:12 elexisvenator

Blank name attribute after selecting file is unwanted behavior at all.

creocoder avatar Dec 18 '14 09:12 creocoder

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

jasny avatar Sep 24 '19 09:09 jasny