I am using blueimp fileupload plugin which works fine in chrome,although same is not working in IE less then IE10.I am getting a prompts to open or save json result.After searching i tried few solution. like one here:-https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation ,but no luck.
I am using Spring3.1,AngularJS. with my 1st approach i am able to upload file,although getting prompts to open or save json in IE as result also
Content-Type application/json;charset=UTF-8output Json returned is
ExcelUpload={UnprocessedRequests=12,AcceptedRequests=0, processedFlag=T,RejectedRequests=0,result=Excel_13}
Spring code is
@RequestMapping(value = "/saveExcel", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> saveExcelDetails(@RequestParam(value="file",required=false) MultipartFile file,HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> excelUpload = myService.saveExcelDetails(request,file);
response.setHeader("Content-Type", "text/html; charset=utf-8");
return excelUpload;
}
then i tried 2nd approach
@RequestMapping(value = "/saveExcel", method = RequestMethod.POST,**produces = "text/html"**)
public @ResponseBody Map<String, Object> saveExcelDetails(@RequestParam(value="file",required=false) MultipartFile file,HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> excelUpload = myService.saveExcelDetails(request,file);
return excelUpload;
}
but getting error as "Could not find acceptable representation" am i missing something here
Iframe based uploads require a Content-type of text/plain or text/html for the JSON response - they will show an undesired download dialog if the iframe response is set to application/json.we can make use of the Accept header to offer different content types for the file upload response.
how can i achieve
to make use of the Accept header to offer different content types for the file upload response.
in my scenario(code).
Eric i changed it as you suggested
public @ResponseBody Map<String, Object>saveExcelDetails(@RequestParam(value="file",required=false) MultipartFile file,HttpServletRequest request, HttpServletResponse response,@RequestHeader(value="Accept") String accept) throws Exception {
Map<String, Object> excelUpload = myService.saveExcelDetails(request,file);
if (accept.indexOf("application/json") != -1) {
response.setContentType("application/json; charset=UTF-8");
} else {
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type","text/plain; charset=UTF-8");
}
return excelUpload;
}
done setting response content type as "text/plain", also to the response Header still no luck.