perf:FileUploadPath兼容http地址
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 随机生成一个文件路径
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user