Commit fd6ca746fa2fc42e528d6c0eb46ae5f8ac075244
1 parent
4580bcf8
feat:【infra 基础设施】writeAttachment 根据 contentType 设置其内容显示倾向 https://github.com/Yun…
…aiV/ruoyi-vue-pro/issues/692
Showing
1 changed file
with
7 additions
and
1 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtils.java
| ... | ... | @@ -80,9 +80,15 @@ public class FileTypeUtils { |
| 80 | 80 | */ |
| 81 | 81 | public static void writeAttachment(HttpServletResponse response, String filename, byte[] content) throws IOException { |
| 82 | 82 | // 设置 header 和 contentType |
| 83 | - response.setHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(filename)); | |
| 84 | 83 | String contentType = getMineType(content, filename); |
| 85 | 84 | response.setContentType(contentType); |
| 85 | + // 设置内容显示、下载文件名:https://www.cnblogs.com/wq-9/articles/12165056.html | |
| 86 | + if (StrUtil.containsIgnoreCase(contentType, "image/")) { | |
| 87 | + // 参见 https://github.com/YunaiV/ruoyi-vue-pro/issues/692 讨论 | |
| 88 | + response.setHeader("Content-Disposition", "inline;filename=" + HttpUtils.encodeUtf8(filename)); | |
| 89 | + } else { | |
| 90 | + response.setHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(filename)); | |
| 91 | + } | |
| 86 | 92 | // 针对 video 的特殊处理,解决视频地址在移动端播放的兼容性问题 |
| 87 | 93 | if (StrUtil.containsIgnoreCase(contentType, "video")) { |
| 88 | 94 | response.setHeader("Content-Length", String.valueOf(content.length)); | ... | ... |