Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valums file-uploader doesn't work under Internet Explorer 9

Valums file-uploader (now called Fine Uploader) doesn't work under Internet Explorer 9 but wors fine under Chrome.

So under IE it shows the name of the file and button CANCEL and no % of uploading.

Any clue?

enter image description here


UPDATES:

Solution is here as well MVC Valums Ajax Uploader - IE doesn't send the stream in request.InputStream

like image 781
Friend Avatar asked Mar 27 '12 02:03

Friend


2 Answers

I know this question was filed under asp.net specifically, but it came up when I searched for "valums ajax upload IE9", so I'll post my fix here in case it helps anyone like myself regardless of language:

I was returning a JSON response from the AJAX upload request with a "application/json" content header. IE9 does not know what to do with "application/json" content (but Chrome/FF/etc do).

I fixed this by making sure to return a "text/html" MIME type http header on my json response from the server.

Now IE is no longer trying to download the response! Cheers

like image 132
thaddeusmt Avatar answered Sep 27 '22 22:09

thaddeusmt


I am unable to reproduce the issue. Here's a full working example.

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Upload(HttpPostedFileBase qqfile)
    {
        var uploadPath = Server.MapPath("~/app_data");
        if (qqfile != null)
        {
            var filename = Path.Combine(uploadPath, Path.GetFileName(qqfile.FileName));
            qqfile.SaveAs(filename);
            return Json(new { success = true }, "text/html");
        }
        else 
        {
            var filename = Request["qqfile"];
            if (!string.IsNullOrEmpty(filename))
            {
                filename = Path.Combine(uploadPath, Path.GetFileName(filename));
                using (var output = System.IO.File.Create(filename))
                {
                    Request.InputStream.CopyTo(output);
                }
                return Json(new { success = true });
            }
        }
        return Json(new { success = false });
    }
}

Index.cshtml view:

<script src="@Url.Content("~/Scripts/valums/fileuploader.js")" type="text/javascript"></script>

<div id="file-uploader">       
    <noscript>          
        <p>Please enable JavaScript to use file uploader.</p>
    </noscript>         
</div>

<script type="text/javascript">
    var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader'),
        action: '@Url.Action("upload")'
    });
</script>

You could also include the CSS in your Layout:

<link href="@Url.Content("~/Scripts/valums/fileuploader.css")" rel="stylesheet" type="text/css" />
like image 41
Darin Dimitrov Avatar answered Sep 27 '22 21:09

Darin Dimitrov