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");
地址:https://www.leftso.com/article/989.html