今天在IE8测试文件上传的时候发现总是提示下载,原因是上传接口返回的是json,通过以下修改就可以保证返回是json并且不会出现下载的情况:
@RequestMapping(value = "/batchUpload", method = RequestMethod.POST,produces = "text/json;charset=UTF-8") @ResponseBody public Object batchUpload(@RequestParam String orderId, @RequestParam("file") MultipartFile file, HttpServletResponse response) { response.setHeader("Cache-Control", "no-cache"); response.setHeader("X-Frame-Options", "SAMEORIGIN"); response.setHeader("Access-Control-Allow-Origin", "*"); String filePath = fileUploadService.upload(file); Map result = new HashedMap(); if (filePath == null) { result.put("status", 0); } else { result.put("status", 1); result.put("filePath", filePath); } return JSON.toJSONString(result); }
What is the exact difference between content-type: text/json and application/json?
application/json
: Official MIME type for json
text/x-json
: Experimental(unofficial) MIME type for json before application/json got officially registered
仅此而已