fix:修复中文文件名找不到文件问题
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
# 任务执行摘要
|
||||||
|
|
||||||
|
## 会话 ID: 1
|
||||||
|
- [2026-05-13 10:30:00]
|
||||||
|
- **执行原因**: onlinePreview 接口中,URL 指向的公网文件过大导致下载缓慢,但这些文件实际就存放在当前服务器的 /home/img 目录下,需要优先使用本地文件。
|
||||||
|
- **执行过程**:
|
||||||
|
1. 在 OnlinePreviewController 中添加了 LOCAL_FILE_ROOT 常量(/home/img)和 checkLocalFile 辅助方法。
|
||||||
|
2. 在 onlinePreview 方法中,URL 解码后调用 checkLocalFile 检查本地是否存在对应文件。
|
||||||
|
3. checkLocalFile 解析 HTTP URL 的 path 部分(如 /userfiles/a68315b5947c4b8abe9b54b3af41a7d2/contractsPayment/2026/5/10.%E5%8F%91%E7%A5%A8%E6%9F%A5%E9%AA%8C.pdf),URL 解码后拼接在 /home/img 下,若文件存在则返回 file:// 协议的本地路径。
|
||||||
|
- **执行结果**: 当本地 /home/img 下存在与公网 URL 路径一致的文件时,优先使用本地文件,避免从公网重复下载大文件。
|
||||||
|
|
||||||
|
## 会话 ID: 2
|
||||||
|
- [2026-05-14 10:00:00]
|
||||||
|
- **执行原因**: 本地 file:// 路径中包含中文文件名时,urlEncoderencode 会将中文重新编码为百分号编码(如 日程 → %E6%97%A5%E7%A8%8B),导致文件系统无法找到该文件。
|
||||||
|
- **执行过程**:
|
||||||
|
1. 排查发现 urlEncoderencode 方法会调用 URLEncoder.encode 对整个 URL 编码,中文被转回百分号编码。
|
||||||
|
2. 在 onlinePreview 方法中增加判断:当 fileUrl 以 file:// 开头时,跳过 urlEncoderencode 调用。
|
||||||
|
- **执行结果**: 本地文件路径中的中文字符保持原样,文件系统能正确找到文件。
|
||||||
@@ -97,7 +97,9 @@ public class OnlinePreviewController {
|
|||||||
model.addAttribute("file", fileAttribute);
|
model.addAttribute("file", fileAttribute);
|
||||||
FilePreview filePreview = previewFactory.get(fileAttribute);
|
FilePreview filePreview = previewFactory.get(fileAttribute);
|
||||||
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
|
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
|
||||||
fileUrl =WebUtils.urlEncoderencode(fileUrl);
|
if (!fileUrl.startsWith("file://")) {
|
||||||
|
fileUrl = WebUtils.urlEncoderencode(fileUrl);
|
||||||
|
}
|
||||||
if (ObjectUtils.isEmpty(fileUrl)) {
|
if (ObjectUtils.isEmpty(fileUrl)) {
|
||||||
return otherFilePreview.notSupportedFile(model, "非法路径,不允许访问");
|
return otherFilePreview.notSupportedFile(model, "非法路径,不允许访问");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user