From 5d263d0b58400439c5c881adbaa8ba689b3a1ff0 Mon Sep 17 00:00:00 2001 From: airbo Date: Fri, 19 Aug 2022 15:58:12 +0800 Subject: [PATCH] fix: Qiniuoss cannot upload non image attachments (#2331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug #### What this PR does / why we need it: 发现在七牛的 [QiniuOssFileHandler:145](https://github.com/halo-dev/halo/blob/f8bd4febb9ee59847e1d199b10f3be7ae1c95320/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java#L145-L152) 行中,如果文件不是图片类型的话就跳过了setThumbPath 但是在其他文件存储的handler中(如:本地 [LocalFileHandler:125](https://github.com/halo-dev/halo/blob/f8bd4febb9ee59847e1d199b10f3be7ae1c95320/src/main/java/run/halo/app/handler/file/LocalFileHandler.java#L125), [TencentCosFileHandler:128](https://github.com/halo-dev/halo/blob/f8bd4febb9ee59847e1d199b10f3be7ae1c95320/src/main/java/run/halo/app/handler/file/TencentCosFileHandler.java#L128))调用了handleImageMetadata default方法,该方法最后判断 thumbPath 为空时会将其设为 filePath 故在七牛云handler使用了handleImageMetadata 方法,使得其他类型文件也可以setThumbPath,并成功上传不会引发错误 #### Which issue(s) this PR fixes: Fixes #2320 #### Special notes for your reviewer: 看到其他文件handler中[TencentCosFileHandler:130](https://github.com/halo-dev/halo/blob/f8bd4febb9ee59847e1d199b10f3be7ae1c95320/src/main/java/run/halo/app/handler/file/TencentCosFileHandler.java#L130)有一个 `uploadResult.setThumbPath(fullPath);` 好像是没有必要的,也在[HuaweiObsFileHandler](https://github.com/halo-dev/halo/blob/f8bd4febb9ee59847e1d199b10f3be7ae1c95320/src/main/java/run/halo/app/handler/file/HuaweiObsFileHandler.java#L116-L123)中不存在上述代码。 #### Does this PR introduce a user-facing change? ```release-note 修复了七牛云做附件存储时附件无法上传非图片文件的问题 ``` --- .../halo/app/handler/file/QiniuOssFileHandler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java b/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java index 32f465664..0caedddd2 100644 --- a/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java @@ -142,14 +142,15 @@ public class QiniuOssFileHandler implements FileHandler { result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType()))); result.setSize(file.getSize()); - if (isImageType(file)) { + // Handle thumbnail + handleImageMetadata(file, result, () -> { if (ImageUtils.EXTENSION_ICO.equals(pathDescriptor.getExtension())) { - result.setThumbPath(fullPath); + return fullPath; } else { - result.setThumbPath(StringUtils.isBlank(thumbnailStyleRule) ? fullPath : - fullPath + thumbnailStyleRule); + return StringUtils.isBlank(thumbnailStyleRule) ? fullPath : + fullPath + thumbnailStyleRule; } - } + }); return result; } catch (IOException e) {