开发者

Image upload doesn't work in mozilla and Internet Explorer - asks to save files

I have implemented upload feature in ASP.MVC. I am using jQuery.BlockUI and JQuery.Form plugins (but I don't know is this impor开发者_如何学JAVAtant). And everything works perfect in Google Chrome.

But in Mozilla and Internet Explorer it doesn't. When I try to upload image it asks me in popup window:

Upload. You have chosen to open Upload which is a: application/json from http://localhost:2993 What should Firefox do with this file?

And I have open with/save and browse options.

In my upload method I am returning JSon here is the code:

[HttpPost]
public JsonResult Upload()
{
   string savedFileName = null;
   string hName = null;
   for (int i = 0; i < Request.Files.Count; i++)
   {
      HttpPostedFileBase hpf = Request.Files[i] as HttpPostedFileBase;
      if (hpf.ContentLength == 0)
         continue;

      string savedFileNameThumb = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                   "Content", "Images", "Thumb",
                   Path.GetFileName(hpf.FileName));

      savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                   "Content", "Images", "Full",
                   Path.GetFileName(hpf.FileName));
      hName = hpf.FileName;

      ImageModel.ResizeAndSave(savedFileName, hpf.FileName, hpf.InputStream, int.MaxValue, false);
      // for cropping
      ImageModel.ResizeAndSave(savedFileName, hpf.FileName, hpf.InputStream, 540, false);
   }

   string r = string.Format("../../Content/Images/Full/{0}", hName);
   return Json(new { foo = r });
}

What produce this error?


You are returning JSON as the page to the user following the upload. The JSON won't make any sense to a regular user, so most browsers doesn't have any predefined way to display the JSON.

If the returned page is displayed somewhere, you should return a regular HTML page that means something to the user. If the page isn't really displayed somewhere (e.g. loaded in a hidden frame), you should return an empty HTML page that all browsers know how to display.


Here's the actual fix. In the case that you're doing an asynchronous iframe upload (which is the standard AJAX way of uploading files in the background) you have to set the response type on the server side to "text/html" not "text/json"

http://www.sencha.com/forum/archive/index.php/t-120201.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜