Handle thumbnail while media type of the file is an image type

pull/137/head
johnniang 2019-03-27 09:19:24 +08:00
parent 3c56b60b95
commit ab58e800c4
1 changed files with 6 additions and 3 deletions

View File

@ -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) {