Question

I'm trying to use the Kendo UI Upload (MVC wrapper) in async mode. Things seem to work fine in Chrome, but no such luck in IE (as of now only tested in IE 9). When it initiates the upload, I can see it hitting my action method and the request contains the data I expect, but nothing is actually being saved.

Code samples are below:

_EditForm.cshtml (where the upload is)

@(Html.Kendo().Upload()
    .Name(string.Format("upload{0}", "background"))
    .Multiple(true)
    .Events(evt => evt.Success("refreshBackgroundImages"))
    .Messages(msg => msg.DropFilesHere("drag and drop images from your computer here")
                        .StatusUploaded("Files have been uploaded"))
    .Async(a => a.AutoUpload(true)
                 .SaveField("files")
                 .Save("UploadImage", "Packages", new { siteId = Model.WebsiteId, type = "background" })))

Controller ActionMethod

[HttpPost]
public ActionResult UploadImage(IEnumerable<HttpPostedFileBase> files, Guid siteId, string type)
{
        var site = _websiteService.GetWebsite(siteId);
        var path = Path.Combine(_fileSystem.OutletVirtualPath, site.Outlet.AssetBaseFolder);
        if (type == "background")
        {
            path = Path.Combine(path, _backgroundImageFolder);
        }
        else if (type == "image")
        {
            path = Path.Combine(path, _foregroundImageFolder);
        }
        foreach (var file in files)
        {
            _fileSystem.SaveFile(path, file.FileName, file.InputStream, file.ContentType, true);
        }
        // Return empty string to signify success
        return Content("");
}
Was it helpful?

Solution

Well as another post said, "Welcome to episode 52,245,315 of 'Why Does Internet Explorer suck so badly':

Turns out that when you do file.FileName on an HttpPostedFileBase in Internet Explorer, it thinks you want the whole path of the file on the local machine. It's obviously an IE only thing as Chrome and Firefox seem to have it right.

Make sure to do the following when you only want the actual FileName:

var filename = Path.GetFileName(file.FileName);

OTHER TIPS

The problem is when you actually try to save a file and send back a success response from the server. I don't think your demos are doing any of that. The iframe in ie9 does not receive the response from the server. The browser thinks the response is a download even though it's just a plain text json response. I debugged it down to the fact that the on load event on the iframe never gets fired so the onload handler that needs to handle this response is not doing anything. In all other browsers this is working.

Source: http://www.kendoui.com/forums/kendo-ui-web/upload/async-uploader-and-ie-9-not-working.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top