Проблема в том, что Internet Explorer 8 не поддерживает закачку файлов на сервер с помощью XMLHttpRequest.
Для того чтобы обойти эту проблему jQuery File Upload Plugin использует закачку файлов на основе iframe (был такой древний способ).
Подобный способ закачивания файлов на сервер требует Content-Type : text/plain или Content-Type : text/html для ответов в формате JSON, в противном случае будет отображаться окно скачивания файла.
Официальное описание проблемы: https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
Это значит, что на сервере мы должны проверять версию браузера и для Internet Explorer 8 возвращать свой Content-Type.
Пример для Spring MVC с Apache Commons FileUpload:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
... public static class MyResponse { private boolean success; private String message; public boolean getSuccess() { return this.success; } public void setSuccess(boolean success) { this.success = success; } public String getMessage() { return this.message; } public void setMessage() { this.message = message; } } @POST @Path("upload") public void uploadFile(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { HttpServletRequest httpServletRequest; HttpServletResponse httpServletResponse; ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); if (requestAttributes == null) { httpServletRequest = null; httpServletResponse = null; } else { httpServletRequest = requestAttributes.getRequest(); httpServletResponse = requestAttributes.getResponse(); } boolean ie8Workaround = false; // IE 8 не поддерживает загрузку файлов с XMLHttpRequest // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation if (httpServletRequest != null) { logger.debug("importCsv userAgent: " + httpServletRequest.getHeader("User-Agent")); logger.debug("importCsv accept: " + httpServletRequest.getHeader("Accept")); String userAgentHeader = httpServletRequest.getHeader("User-Agent"); if (userAgentHeader != null && userAgentHeader.contains("MSIE 8.0")) { ie8Workaround = true; } } // ... Обработка файла MyResponse result = new MyResponse(); result.setSuccess(true); if (ie8Workaround) { httpServletResponse.setContentType("text/html"); } else { httpServletResponse.setContentType("application/json; charset=utf-8"); } // Мы используем Jackson JSON для сериализации объектов в JSON. ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectWriter = objectMapper.writer(); byte[] data = objectWriter.writeValueAsBytes(result); httpServletResponse.getOutputStream().write(data); httpServletResponse.setContentLength(data.length); httpServletResponse.getOutputStream().flushBuffer(); } ... |
Ðe best way is to kill IE8 wið ðe dragonflame!!!
And never use it!