fix(AliOssController): 根据文件类型修正缩略图和预览图逻辑

- 获取上传文件的 contentType 以判断文件类型
- 图片类型时生成带图片处理参数的缩略图和预览图
- 视频类型时生成视频截帧的缩略图,预览图使用原始 URL
- 其他类型文件直接使用原始文件 URL 作为缩略图和预览图
- 避免非图片文件拼接图片处理参数导致显示异常
This commit is contained in:
2026-06-28 13:07:27 +08:00
parent 13c48df4b3
commit b8c147c641
2 changed files with 34 additions and 2 deletions

View File

@@ -155,11 +155,27 @@ public class AliOssController extends BaseController {
result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName);
result.setLength(upload.length());
result.setPath(bucketDomain + path);
result.setThumbnail(bucketDomain + path + "?x-oss-process=image/resize,m_fixed,w_100,h_100/quality,Q_90");
result.setUrl(bucketDomain + path + "?x-oss-process=image/resize,w_750/quality,Q_90");
result.setDownloadUrl(bucketDomain + path);
// 获取文件类型
String contentType = FileServerUtil.getContentType(upload);
result.setContentType(contentType);
// 根据文件类型设置缩略图和预览图
if (FileServerUtil.isImage(contentType)) {
// 图片:生成缩略图和压缩预览图
result.setThumbnail(bucketDomain + path + "?x-oss-process=image/resize,m_fixed,w_100,h_100/quality,Q_90");
result.setUrl(bucketDomain + path + "?x-oss-process=image/resize,w_750/quality,Q_90");
} else if (contentType != null && contentType.startsWith("video/")) {
// 视频使用OSS视频截帧生成缩略图取首帧
result.setThumbnail(bucketDomain + path + "?x-oss-process=video/snapshot,t_0,f_jpg,w_100,h_100,m_fast");
result.setUrl(bucketDomain + path);
} else {
// 非图片/视频直接使用原始URL
result.setThumbnail(bucketDomain + path);
result.setUrl(bucketDomain + path);
}
result.setTenantId(Integer.valueOf(tenantId));
upload.delete();
fileRecordService.save(result);