mirror of https://github.com/halo-dev/halo
Handle thumbnail while media type of the file is an image type
parent
3c56b60b95
commit
ab58e800c4
|
@ -57,7 +57,7 @@ public class FileServiceImpl implements FileService {
|
||||||
private final MediaType imageType = MediaType.valueOf("image/*");
|
private final MediaType imageType = MediaType.valueOf("image/*");
|
||||||
|
|
||||||
public FileServiceImpl(HaloProperties haloProperties,
|
public FileServiceImpl(HaloProperties haloProperties,
|
||||||
OptionService optionService) throws URISyntaxException {
|
OptionService optionService) {
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
|
|
||||||
// Get work dir
|
// Get work dir
|
||||||
|
@ -146,7 +146,7 @@ public class FileServiceImpl implements FileService {
|
||||||
uploadResult.setSize(file.getSize());
|
uploadResult.setSize(file.getSize());
|
||||||
|
|
||||||
// Check file type
|
// Check file type
|
||||||
if (isImageType(file.getContentType())) {
|
if (isImageType(uploadResult.getMediaType())) {
|
||||||
// Upload a thumbnail
|
// Upload a thumbnail
|
||||||
String thumbnailBasename = basename + '-' + "thumbnail";
|
String thumbnailBasename = basename + '-' + "thumbnail";
|
||||||
String thumbnailSubFilePath = subDir + thumbnailBasename + '.' + extension;
|
String thumbnailSubFilePath = subDir + thumbnailBasename + '.' + extension;
|
||||||
|
@ -230,12 +230,15 @@ public class FileServiceImpl implements FileService {
|
||||||
UploadResult result = new UploadResult();
|
UploadResult result = new UploadResult();
|
||||||
result.setFilename(putSet.getHash());
|
result.setFilename(putSet.getHash());
|
||||||
result.setFilePath(filePath);
|
result.setFilePath(filePath);
|
||||||
result.setThumbPath(StringUtils.isBlank(smallUrl) ? filePath : filePath + smallUrl);
|
|
||||||
result.setSuffix(FilenameUtils.getExtension(file.getOriginalFilename()));
|
result.setSuffix(FilenameUtils.getExtension(file.getOriginalFilename()));
|
||||||
result.setWidth(putSet.getWidth());
|
result.setWidth(putSet.getWidth());
|
||||||
result.setHeight(putSet.getHeight());
|
result.setHeight(putSet.getHeight());
|
||||||
result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
result.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
||||||
|
|
||||||
|
if (isImageType(result.getMediaType())) {
|
||||||
|
result.setThumbPath(StringUtils.isBlank(smallUrl) ? filePath : filePath + smallUrl);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e instanceof QiniuException) {
|
if (e instanceof QiniuException) {
|
||||||
|
|
Loading…
Reference in New Issue