mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-08 17:27:34 +00:00
修复编码转换问题
This commit is contained in:
@@ -199,14 +199,16 @@ public class FileHandlerService implements InitializingBean {
|
|||||||
String baseUrl = BaseUrlFilter.getBaseUrl();
|
String baseUrl = BaseUrlFilter.getBaseUrl();
|
||||||
pdfFilePath = pdfFilePath.replace(fileDir, "");
|
pdfFilePath = pdfFilePath.replace(fileDir, "");
|
||||||
String pdfFolder = pdfFilePath.substring(0, pdfFilePath.length() - 4);
|
String pdfFolder = pdfFilePath.substring(0, pdfFilePath.length() - 4);
|
||||||
String urlPrefix;
|
// 对整个路径进行编码,包括特殊字符
|
||||||
try {
|
String encodedPath = URLEncoder.encode(pdfFolder, StandardCharsets.UTF_8);
|
||||||
urlPrefix = baseUrl + URLEncoder.encode(pdfFolder, uriEncoding).replaceAll("\\+", "%20");
|
encodedPath = encodedPath
|
||||||
} catch (UnsupportedEncodingException e) {
|
.replaceAll("%2F", "/") // 恢复斜杠
|
||||||
logger.error("UnsupportedEncodingException", e);
|
.replaceAll("%5C", "/") // 恢复反斜杠
|
||||||
urlPrefix = baseUrl + pdfFolder;
|
.replaceAll("\\+", "%20"); // 空格处理
|
||||||
}
|
// 构建URL:使用_作为分隔符(这是kkFileView压缩包预览的常见格式)
|
||||||
return urlPrefix + "/" + index + PDF2JPG_IMAGE_FORMAT;
|
String url = baseUrl + encodedPath + "/" + index + PDF2JPG_IMAGE_FORMAT;
|
||||||
|
return url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,11 +61,10 @@ public class WebUtils {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static String encodeFileName(String name) {
|
public static String encodeFileName(String name) {
|
||||||
try {
|
name = URLEncoder.encode(name, StandardCharsets.UTF_8)
|
||||||
name = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20");
|
.replaceAll("%2F", "/") // 恢复斜杠
|
||||||
} catch (UnsupportedEncodingException e) {
|
.replaceAll("%5C", "/") // 恢复反斜杠
|
||||||
return null;
|
.replaceAll("\\+", "%20"); // 空格处理
|
||||||
}
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user