春季:图像不会在IE中加载Etag

时间:2019-04-26 08:22:12

标签: java spring internet-explorer etag

我正在一个Spring-MVC项目中,在该项目中,我具有用于加载图像的Etag功能。它适用于所有其他浏览器,除了每个人都喜欢的IE-11。图像显示为断开的链接。我哪里做错了?

代码:

@RequestMapping(value = "/getminipreview")
    @ResponseBody
    public int getminipreview(){

     Calendar inOneMonth = Calendar.getInstance();
            inOneMonth.add(Calendar.MONTH, 1);
            Path path;

      if(file!=null) {
                String etag = "";
                File etagFile = new File("/etag/file/location");
                if(!etagFile.exists()){
                   etag = java.util.UUID.randomUUID().toString();
                     (Writer writer = new BufferedWriter(new OutputStreamWriter(
                            new FileOutputStream(etagFile), StandardCharsets.UTF_8))) {
                        writer.write(etag);
                        response.addHeader("Etag",etag);
                    }

                }else {
                    etag = new String(Files.readAllBytes(etagFile.toPath()));
                    response.addHeader("Etag",etag);
                }

                response.setHeader("Cache-Control" , "no-cache, no-store, must-revalidate");
                response.setContentType("image/png");
                response.setDateHeader("Expires",inOneMonth.getTimeInMillis());
                response.setHeader("Content-Disposition", "attachment; filename=\"" + "image.png" + "\"");
                response.addHeader("X-Content-Type-Options","nosniff");
                response.setHeader("Content-Type", "image/png");
                response.setContentLength((int) Files.size(path));
                Files.copy(path, response.getOutputStream());
            }

0 个答案:

没有答案