From ab58e800c4d84e58a160112074e265849c11832b Mon Sep 17 00:00:00 2001 From: johnniang Date: Wed, 27 Mar 2019 09:19:24 +0800 Subject: [PATCH] Handle thumbnail while media type of the file is an image type --- .../java/cc/ryanc/halo/service/impl/FileServiceImpl.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/ryanc/halo/service/impl/FileServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/FileServiceImpl.java index 51f72b92d..a4699b58a 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/FileServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/FileServiceImpl.java @@ -57,7 +57,7 @@ public class FileServiceImpl implements FileService { private final MediaType imageType = MediaType.valueOf("image/*"); public FileServiceImpl(HaloProperties haloProperties, - OptionService optionService) throws URISyntaxException { + OptionService optionService) { this.optionService = optionService; // Get work dir @@ -146,7 +146,7 @@ public class FileServiceImpl implements FileService { uploadResult.setSize(file.getSize()); // Check file type - if (isImageType(file.getContentType())) { + if (isImageType(uploadResult.getMediaType())) { // Upload a thumbnail String thumbnailBasename = basename + '-' + "thumbnail"; String thumbnailSubFilePath = subDir + thumbnailBasename + '.' + extension; @@ -230,12 +230,15 @@ public class FileServiceImpl implements FileService { UploadResult result = new UploadResult(); result.setFilename(putSet.getHash()); result.setFilePath(filePath); - result.setThumbPath(StringUtils.isBlank(smallUrl) ? filePath : filePath + smallUrl); result.setSuffix(FilenameUtils.getExtension(file.getOriginalFilename())); result.setWidth(putSet.getWidth()); result.setHeight(putSet.getHeight()); result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType()))); + if (isImageType(result.getMediaType())) { + result.setThumbPath(StringUtils.isBlank(smallUrl) ? filePath : filePath + smallUrl); + } + return result; } catch (IOException e) { if (e instanceof QiniuException) {