add(req-2080):创建linux服务器临时目录
This commit is contained in:
parent
e7adaa2d9a
commit
1bfc319140
@ -642,14 +642,16 @@ public class FileServiceImpl implements FileService {
|
|||||||
input = file.getInputStream();
|
input = file.getInputStream();
|
||||||
// 指定目标文件路径及文件名
|
// 指定目标文件路径及文件名
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
|
String osName = System.getProperty("os.name");
|
||||||
|
String rootDir = null;
|
||||||
|
if (Objects.nonNull(osName) && osName.toLowerCase().startsWith("linux")) {
|
||||||
|
rootDir = "/mnt/tem/obs";
|
||||||
|
} else {
|
||||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||||
String classPath = Objects.requireNonNull(contextClassLoader.getResource("")).getPath();
|
String classPath = Objects.requireNonNull(contextClassLoader.getResource("")).getPath();
|
||||||
log.info("linux服务器下的类文件路径:{}", classPath);
|
rootDir = classPath.substring(0, classPath.indexOf("/target/classes/"));
|
||||||
String projectPath = classPath.substring(0, classPath.indexOf("/target/classes/"));
|
}
|
||||||
log.info("linux服务器下的项目路径:{}", projectPath);
|
String filePath = rootDir + SEPARATOR + "temp_directory";
|
||||||
|
|
||||||
String filePath = projectPath + SEPARATOR + "temp_directory";
|
|
||||||
String absolutePath = filePath + SEPARATOR + fileName;
|
String absolutePath = filePath + SEPARATOR + fileName;
|
||||||
|
|
||||||
// 创建临时文件夹
|
// 创建临时文件夹
|
||||||
@ -661,12 +663,12 @@ public class FileServiceImpl implements FileService {
|
|||||||
} else {
|
} else {
|
||||||
log.info("临时文件夹创建失败,{}", flag);
|
log.info("临时文件夹创建失败,{}", flag);
|
||||||
// 兜底
|
// 兜底
|
||||||
absolutePath = projectPath + SEPARATOR + fileName;
|
absolutePath = rootDir + SEPARATOR + fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tempDirectory.exists()) {
|
if (!tempDirectory.exists()) {
|
||||||
// 兜底
|
// 兜底
|
||||||
absolutePath = projectPath + SEPARATOR + fileName;
|
absolutePath = rootDir + SEPARATOR + fileName;
|
||||||
}
|
}
|
||||||
log.info("临时文件绝对路径:{}", absolutePath);
|
log.info("临时文件绝对路径:{}", absolutePath);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user