I have implemented upload feature in ASP.MVC. I am using jQuery.BlockUI and JQuery.Form plugins (but I don’t know is this important). 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.