This commit is contained in:
zwt13703
2026-05-14 09:17:19 +08:00
parent a62d2fd664
commit 9313898f6c
3 changed files with 12 additions and 6 deletions
@@ -256,7 +256,7 @@ public class FileHandlerService {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}else {
}else if (!url.startsWith("file://")) {
url = Objects.requireNonNull(WebUtils.encodeUrlFileName(url))
.replaceAll("\\+", "%20")
.replaceAll("%3A", ":")
@@ -14,6 +14,8 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.UUID;
@@ -153,7 +155,8 @@ public class DownloadUtils {
// 处理file协议的文件下载
private static void handleFileProtocol(URL url, String targetPath) throws IOException {
File sourceFile = new File(url.getPath());
String path = URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8);
File sourceFile = new File(path);
if (!sourceFile.exists()) {
throw new FileNotFoundException("本地文件不存在: " + url.getPath());
}