perf:FileUploadPath兼容http地址

This commit is contained in:
曾文豪
2023-01-11 14:40:27 +08:00
parent a585a68194
commit c6ee1f2279
2 changed files with 33 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
public class FileUploadPath {
@@ -29,6 +30,10 @@ public class FileUploadPath {
* @return
*/
public static FileUploadPath get(String fileName) {
// 下载文件
fileName = downloadFile(fileName);
FileUploadPath pathBean = new FileUploadPath();
String tempPath = fileName;
@@ -43,6 +48,26 @@ public class FileUploadPath {
}
/**
* 下载http文件
*
* @param fileName
* @return
*/
public static String downloadFile(String fileName) {
if (!StrUtil.startWith(fileName, "http")) {
return fileName;
}
String newFileName = UPLOAD_FOLDER + StrUtil.subAfter(fileName, UPLOAD_FOLDER, true);
FileUploadPath uploadPath = get(newFileName);
if (!FileUtil.exist(uploadPath.getAbsolutePath())) {
HttpUtil.downloadFile(fileName, uploadPath.getAbsolutePath());
}
return uploadPath.getHttpPath();
}
/**
* 随机生成一个文件路径
*