Whenever I try to upload using Blueimp jQuery File Upload on Internet Explore 6/9, ASP.NET cannot find the files in the request. I have basic code which looks like

[HttpPost]
public JsonResult Images()
{
    HttpPostedFileBase file = Request.Files[0] as HttpPostedFileBase;
}

My jQuery looks like:

$('#fileupload').fileupload({
                    //forceIframeTransport: true,
                    //contentType: 'multipart/form-data',
                    //replaceFileInput: false,
                    //contentType: 'text/plain',
                    //dataType: 'text/plain',
                    url: '@Url.Action("Images", "Upload")',
                    //autoUpload: true,
                    done: function (e, data) {
                        $('.file_result').html('');
                        $('.file_result').append(data.result.text + "<br>");
                    }
                });

The first part is when it's working and the second is when I'm using IE7-9. enter image description here

有帮助吗?

解决方案

Usually this kind of problems are due for not including jquery.iframe-transport.js.

The plugin makes use of an Iframe Transport module for browsers like Microsoft Internet Explorer and Opera, which do not support XMLHTTPRequest file uploads in earlier versions.

Another problem I see in your code is that you are not setting the contentType and dataType in your javascript code and your response Content-type should be text/plain

There you can find 2 working implementation for reference:

http://www.webtrendset.com/2011/06/22/complete-code-example-for-using-blueimp-jquery-file-upload-control-in-asp-net/

https://github.com/i-e-b/jQueryFileUpload.Net

其他提示

I had an issue similar to this one, so hopefully the resolution will help someone out:

What I'm doing is sending the files to a web method in a WCF service, and then just writing them to a folder on the web server. Everything worked fine in Firefox and Chrome, but with IE (unfortunately we're required to support IE), the file content was being sent in the header, but not written on the server.

When I looked at the traffic with Fiddler, what ended up happening is that when the request was sent with IE, the FileName property was "C:\somelocalclientfolder\somefile.txt" in the HttpContext request. In Chrome and Firefox, it was just "somefile.txt". I added in some statements to parse and extract just the filename, and poof, problem solved. File gets successfully written in IE, Chrome, and Firefox.

Also, as others have mentioned, you need to set the response Content-Type to "text/plain" if the request is made with IE. .NET has some classes that will return the type of browser used to make the request, so I just use those to determine server-side if IE is making the request and then only set the Content-Type to "text/plain" for that specific situation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top