feat(req-2080):代码优化
This commit is contained in:
parent
c82b0e3d52
commit
492896278e
@ -644,17 +644,25 @@ public class FileServiceImpl implements FileService {
|
||||
input = file.getInputStream();
|
||||
// 指定目标文件路径及文件名
|
||||
String fileName = file.getOriginalFilename();
|
||||
|
||||
// 生成临时文件名称,防止中文文件名乱码导致删除失败
|
||||
assert fileName != null;
|
||||
String tempFileName = Utility.getUUID() + fileName.substring(fileName.lastIndexOf("."));
|
||||
|
||||
// 获取操作系统名称,不同操作系统中文件路径有区别
|
||||
String osName = System.getProperty("os.name");
|
||||
String rootDir;
|
||||
// linux操作系统
|
||||
if (Objects.nonNull(osName) && osName.toLowerCase().startsWith("linux")) {
|
||||
rootDir = "/mnt/temp/obs";
|
||||
} else {
|
||||
// 其它操作系统
|
||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
String classPath = Objects.requireNonNull(contextClassLoader.getResource("")).getPath();
|
||||
rootDir = classPath.substring(0, classPath.indexOf("/target/classes/"));
|
||||
}
|
||||
|
||||
// 拼接文件路径
|
||||
String filePath = rootDir + SEPARATOR + "temp_directory";
|
||||
String absolutePath = filePath + SEPARATOR + tempFileName;
|
||||
|
||||
@ -670,10 +678,6 @@ public class FileServiceImpl implements FileService {
|
||||
absolutePath = rootDir + SEPARATOR + tempFileName;
|
||||
}
|
||||
}
|
||||
if (!tempDirectory.exists()) {
|
||||
// 兜底
|
||||
absolutePath = rootDir + SEPARATOR + tempFileName;
|
||||
}
|
||||
log.info("临时文件绝对路径:{}", absolutePath);
|
||||
|
||||
// 创建输出流并写入数据
|
||||
|
||||
Loading…
Reference in New Issue
Block a user