spring boot 图片在线预览_spring boot 图片查看接口

spring boot 图片在线预览_spring boot 图片查看接口

response.setHeader("Content-Type","application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename="+URLEncoder.encode(ossFile.getFileOriginalName(),"UTF-8"));

当图片不需要在线查看的时候,需要配置上面两个信息

当我们需要在线预览查看图片的时候一定不要设置上面两个属性。

判断是否为图片文件类型:

String contentType = "";
Optional<MediaType> mediaType = MediaTypeFactory.getMediaType(ossFile.getStorageName());
   if(mediaType.isPresent()){
     contentType=mediaType.get().toString();
   }
boolean isImage=contentType.startsWith("image");

图片如果需要在线预览,则通过判断是否为图片后再决定是否添加Content-Type Content-Disposition这两个属性。

关联:spring  boot 下载excel文件提示“文件中部分内容有问题。是否让我们尽量尝试恢复

spring boot 图片在线预览_spring boot 图片查看接口

相关文章:

你感兴趣的文章:

标签云: