From 725503152e16e41a0e875e61402928e9f490b586 Mon Sep 17 00:00:00 2001 From: Timi Date: Tue, 17 Nov 2026 14:26:09 +0800 Subject: [PATCH] fix(attach): lost file name for download --- .../api/modules/common/controller/AttachmentController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/imyeyu/api/modules/common/controller/AttachmentController.java b/src/main/java/com/imyeyu/api/modules/common/controller/AttachmentController.java index a98e1b7..f398da6 100644 --- a/src/main/java/com/imyeyu/api/modules/common/controller/AttachmentController.java +++ b/src/main/java/com/imyeyu/api/modules/common/controller/AttachmentController.java @@ -260,7 +260,9 @@ public class AttachmentController { } private void setDownloadHeader(Attachment attachment) throws UnsupportedEncodingException { - if (attachment != null && TimiSpring.getRequest().getRequestURI().endsWith("/download") && attachment.getName() != null) { + // 路径带 /download 就强制下载:/download/{id} 的结尾是 id,用 endsWith 匹配不到 + boolean download = TimiSpring.getRequest().getRequestURI().contains("/download"); + if (attachment != null && download && attachment.getName() != null) { TimiSpring.getResponse().setHeader("Content-Disposition", Network.getFileDownloadHeader(attachment.getName())); } }