修复图片预览失败问题
This commit is contained in:
+7
@@ -16,6 +16,7 @@ import xtools.app.sys.file.service.SysFileDownloadCallback;
|
|||||||
import xtools.app.sys.file.service.SysFileOptService;
|
import xtools.app.sys.file.service.SysFileOptService;
|
||||||
import xtools.app.sys.model.dto.resp.SysFileResp;
|
import xtools.app.sys.model.dto.resp.SysFileResp;
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
|
import xtools.core.enums.ImageTypeEnum;
|
||||||
import xtools.core.extend.TemplateUtils;
|
import xtools.core.extend.TemplateUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -61,9 +62,15 @@ public class SysCommonFileController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断文件是否为图片
|
||||||
|
ImageTypeEnum imageType = ImageTypeEnum.bySuffix(fileInfo.getFileType());
|
||||||
|
|
||||||
String fileName = URLEncoder.encode(fileInfo.getFileName(), StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
String fileName = URLEncoder.encode(fileInfo.getFileName(), StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
||||||
String contentDisposition = "attachment; filename=\"{}\"; filename*=UTF-8''{}";
|
String contentDisposition = "attachment; filename=\"{}\"; filename*=UTF-8''{}";
|
||||||
response.setHeader("Content-Disposition", TemplateUtils.format(contentDisposition, fileName, fileName));
|
response.setHeader("Content-Disposition", TemplateUtils.format(contentDisposition, fileName, fileName));
|
||||||
|
if (!ImageTypeEnum.UNKNOWN.equals(imageType)) {
|
||||||
|
response.setHeader("Content-Type", imageType.getContentType());
|
||||||
|
}
|
||||||
response.setContentLengthLong(fileInfo.getFileSize());
|
response.setContentLengthLong(fileInfo.getFileSize());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user