修改本地文件保存地址

master
wujingtao 3 years ago
parent 8de7d8bc0a
commit cd6e5f5da8

@ -180,8 +180,9 @@ public class FormdataServiceImpl implements FormdataService {
// 存储音频压缩文件到指定目录下 每次上传以 2021-8-5 为 文件名进行记录 每次记录一天的 并保存记录
//文件名
String fileName = file.getOriginalFilename();
//文件保存地址
String path = buildPathUtils.buildFilePath(fileName);
String path = buildPathUtils.buildFilePath();
OutputStream os = null;
InputStream inputStream = null;
try {

@ -1,6 +1,5 @@
package me.zhengjie.modules.uploadnew.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
@ -13,6 +12,7 @@ import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* @author wjt
* @date 2021/8/6
@ -41,26 +41,26 @@ public class BuildPathUtils {
/**
*
*/
public String buildFilePath(String fileName) {
public String buildFilePath() {
// 获取环境配置信息
OsInfo osInfo = SystemUtil.getOsInfo();
// 定义的时间格式
String timeFormate = DateUtil.today();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");
String timeForMate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(4);
String dirPath;
if (osInfo.isWindows()) {
dirPath = fileBasePathWindows + timeFormate + File.separator + fileName;
dirPath = fileBasePathWindows + timeForMate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isLinux()) {
dirPath = fileBasePathLinux + timeFormate + File.separator + fileName;
dirPath = fileBasePathLinux + timeForMate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isMac()) {
dirPath = fileBasePathMac + timeFormate + File.separator + fileName;
dirPath = fileBasePathMac + timeForMate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
@ -74,13 +74,13 @@ public class BuildPathUtils {
*/
public String buildFileOosPath(String subFixFile) {
// 加一个音频格式不存在的格式通配
if (StringUtils.isBlank(subFixFile)){
if (StringUtils.isBlank(subFixFile)) {
subFixFile = "wav";
}
OsInfo osInfo = SystemUtil.getOsInfo();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String timeFormate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(10) + "." + subFixFile;
String timeFormate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(10) + "." + subFixFile;
String dirPath;
if (osInfo.isWindows()) {
@ -89,12 +89,12 @@ public class BuildPathUtils {
// 构建存储文件
return dirPath;
} else if (osInfo.isLinux()) {
dirPath = timeFormate;
dirPath = timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;
} else if (osInfo.isMac()) {
dirPath = timeFormate;
dirPath = timeFormate;
FileUtil.mkdir(new File(dirPath));
// 构建存储文件
return dirPath;

Loading…
Cancel
Save