Valums file-uploader(现在称为Fine Uploader)在Internet Explorer 9下不起作用,但在Chrome下也不错。
因此,在IE下,它显示文件的名称和按钮CANCEL,并且没有上传的百分比。
有任何线索吗?
更新:
解决方案也在这里MVC Valums Ajax Uploader - IE doesn't send the stream in request.InputStream
答案 0 :(得分:11)
我知道这个问题是专门在asp.net下提出的,但是当我搜索“valums ajax upload IE9”时,它就出现了,所以我会在这里发布我的修复,以防它像我一样帮助任何人,无论语言如何: / p>
我从AJAX上传请求返回一个带有“application / json”内容标头的JSON响应。 IE9不知道如何处理“application / json”内容(但Chrome / FF /等)。
我通过确保从服务器返回我的json响应中的“ text / html ”MIME类型http标头来修复此问题。
现在IE不再尝试下载响应了!干杯
答案 1 :(得分:9)
我无法重现此问题。这是一个完整的工作示例。
控制器:
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
查看:
<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>
您还可以在布局中包含CSS:
<link href="@Url.Content("~/Scripts/valums/fileuploader.css")" rel="stylesheet" type="text/css" />
答案 2 :(得分:0)
似乎是IE缓存问题,如果你正在使用Ajax&amp; GET,在Ajax参数的get参数中添加时间戳值,这样就可以做到这一点:
$.ajax({
url : "http:'//myexampleurl.php' + '?ts=' + new Date().getTime(),
dataType: "json",
contentType: "application/json; charset=utf-8",
.
.
//more stuff
答案 3 :(得分:0)
如果您使用的是java spring
@RequestMapping(value = "/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody YourObject excelUplaod(@RequestHeader("X-File-Name") String filename, InputStream is) {
// chrome or firefox
}
@RequestMapping(value = "/upload", method = RequestMethod.POST,headers="content-type=multipart/*", produces = "text/html")
public @ResponseBody ResponseEntity<YourObject> uploadByMultipart(@RequestParam(value = "qqfile") MultipartFile file) {
// IE
try {
String fileName = file.getOriginalFilename();
InputStream is = file.getInputStream();
// more stuff
} catch (Exception e) {
logger.error("error reading excel file", e);
}
}