From eeb707bd9f350a48ad39eb75820fdecf9b82a432 Mon Sep 17 00:00:00 2001 From: Takagi <1103069291@qq.com> Date: Fri, 7 Mar 2025 15:54:59 +0800 Subject: [PATCH] fix: resolve file extension validation failure issue in editor uploads (#7275) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 2.20.x #### What this PR does / why we need it: 将获取文件名的代码由 `Part.name()` 改为 `FilePart.filename()`。`Part.name()` 在没有覆写 form 时可能无法正确获取到文件的客户端路径。 #### How to test it? 1. 在文章设置 - 附件存储策略 中,设置一个其他的附件存储策略。 2. 测试在富文本编辑器中上传文件是否报错文件类型与后缀不匹配的问题。 #### Which issue(s) this PR fixes: Fixes #7274 #### Does this PR introduce a user-facing change? ```release-note 解决在默认编辑器中上传文件失败的问题 ``` --- .../attachment/endpoint/LocalAttachmentUploadHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/run/halo/app/core/attachment/endpoint/LocalAttachmentUploadHandler.java b/application/src/main/java/run/halo/app/core/attachment/endpoint/LocalAttachmentUploadHandler.java index 3a24fb342..3c0896dfe 100644 --- a/application/src/main/java/run/halo/app/core/attachment/endpoint/LocalAttachmentUploadHandler.java +++ b/application/src/main/java/run/halo/app/core/attachment/endpoint/LocalAttachmentUploadHandler.java @@ -159,8 +159,8 @@ class LocalAttachmentUploadHandler implements AttachmentHandler { var typeValidator = file.content() .next() .handle((dataBuffer, sink) -> { - var mimeType = detectMimeType(dataBuffer.asInputStream(), file.name()); - if (!FileTypeDetectUtils.isValidExtensionForMime(mimeType, file.name())) { + var mimeType = detectMimeType(dataBuffer.asInputStream(), file.filename()); + if (!FileTypeDetectUtils.isValidExtensionForMime(mimeType, file.filename())) { handleFileTypeError(sink, "fileTypeNotMatch", mimeType); return; }