6

I have created a new multiple drag drop file upload control with progress bar. It works great with all browsers, except an issue with IE 10 and above.

When I upload files in IE, most of times jquery async request will not complete. It shows pending. I can see it is pending in IE network debugger window. But in all other browsers it work well. I am clueless what is wrong here. Initally I thought it might be something related to caching. But after adding below parameters on server response. It still goes in pending state

context.Response.AppendHeader("Cache-Control", "no-cache"); // HTTP 1.1
context.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 

enter image description here enter image description here enter image description here

for (var i = 0; i < files.length; i++) {
        var data = new FormData();
        data.append(files[i].name, files[i]);
        uploadFile(handlerurl, data);
    }
function uploadFile(handlerurl, formData) {
                var jqXHR = $.ajax({
                    type: 'POST',
                    url: handlerurl,
                    contentType: false,
                    processData: false,
                    async: true,
                    cache: false,
                    data: formData,                         
                    xhr: function () {   },
                    success: function (result, status, xhr) {   },
                    error: function (xhr, status, error) {   }
          });
}

I am calling this function per file. I am not sure what is wrong with IE.

Edit : After debugging, found out that server breakpoint will hit. but there is no files in context.Request.Files. No files send from jquery/AJAX. You can reproduce this issue by keep upload same file again and again.

6
  • similar kind of question : stackoverflow.com/questions/16976079/… Commented Jan 14, 2015 at 16:24
  • what version of IE were you using? Commented Jan 21, 2015 at 20:04
  • You need to show the code that build the formData object Commented Jan 24, 2015 at 3:21
  • try changing the content type to multipart/form-data and also I don't see a comma after xhr and success definitions and the $.ajax({ --- }); is not closed properly Commented Jan 24, 2015 at 8:31
  • tried, still I can reproduce same issue. Commented Feb 5, 2015 at 6:46

4 Answers 4

1

Problem

While looking for fileupload options via ajax and without posting the whole form, we often come across code in the internet using FormData API, which works perfectly fine on chrome and mozilla but not on IE.

Solution

So the idea is to point the target of the form to an iframe and even bind a load event to the iframe so that you know when the upload is finished and write additional jquery functions. Also you can even hide the iframe and not show the user. But this solution works on IE as well. The code is as below

The code also shows how to post additional data along with the file post.

@{
    ViewBag.Title = "Index";
}
<script src="~/scripts/jquery-1.9.1.min_.js"></script>
<script type="text/javascript">
    function successFunction() {
        alert($('#my_iframe').contents().find('p').html());
    }
    function redirect() {
        //debugger;
        document.getElementById('my_form').target = 'my_iframe'; //'my_iframe' is the name of the iframe
        //document.getElementById('my_form').submit();
        var callback = function () {
            if (successFunction)
                successFunction();
            $('#frame').unbind('load', callback);
        };

        $('#my_iframe').bind('load', callback);
        $('#hfParam').val('id:1');

        $('#my_form').submit();
        //$("#my_form").trigger("submit");

    }
</script>
<h2>Index</h2>
<input type="button" name="action" value="Upload" onclick="redirect();"/>
<form id="my_form" name="my_form" action="/FileUpload/UploadFile" method="POST" enctype="multipart/form-data" >
    <div id="main">
        <input name="my_hidden" id="hfParam" type="hidden" />
        <input name="my_files" id="my_file" type="file" />
        <iframe id='my_iframe' name='my_iframe' src="">
        </iframe>
        <div id="someDiv"></div>
    </div>

</form>


[HttpPost]
        public ActionResult UploadFile()
        {
            ContentResult result = new ContentResult() { Content = "<p></p>", ContentType = "text/html"};
            HttpPostedFileBase postedFile = Request.Files[0];
            try
            {
                result.Content = "<p>" + postedFile.FileName + "</p>";

            }
            catch (System.Exception ex)
            {
                result.Content = ex.Message;
            }
            return result;
        }

From: http://kaushikghosh12.blogspot.com/2014/02/ajax-fileupload-on-all-browsers.html

Sign up to request clarification or add additional context in comments.

1 Comment

How should I show upload progress in progess bar with iframe postback.
0

Did you try passing Absolute URL for handlerUrl?

If your code is written in a standalone js file, absolute URL can help else if the code is written on html then passing the right relative URL will help.

Comments

0

You can crate an iframe and then attach and post your images using this iframe. It will post your image simply but will look like you posted using ajax.

Comments

0

We're using https://blueimp.github.io/jQuery-File-Upload/ works perfectly on IE, of course when you get to IE8-9 then you cant really have Drag 'n Drop fully or even partially supported, but its IE.

fileUpload.fileupload({
     autoUpload: false,
     dataType: 'json',
     url: url,
     uploadTemplateId: null,
     downloadTemplateId: null,
     filesContainer: $('.x-table-uploaded-files tbody'),
     uploadTemplate: function (o) {  ... a.s.o

best of all uploaders i've ever handled. (sorry for the incomplete source, work, cant share to much :/)

    [HttpPost]
    public JsonResult Upload(IEnumerable<HttpPostedFileBase> files, int CId)
    {
        UploadResult result = cf.Handle(files, CId);
        result.ErrorCount = result.files.Count;
        if (result.files.Count > 100)
        {
            result.files = new List<FileErrorResults>();
        }
        return Json(result, JsonRequestBehavior.AllowGet);
    }

That example is a auto upload drag and drop file parser that spits back results realtime after analysis and gives errors of files, while the user is dragging the rest of his files. Supports IE10 and above, of course with IE8-9 you have to click and select files instead of drag and drop, but i guess that is punishment enough that they are using IE.

However i did try to google for a solution for ya, it seems that there were a lot of bugs in the IE teams list for upload pending issues, that files in many scenarios just get stuck. Its a dangerous platform.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.