修改本地文件保存地址

master
wujingtao 3 years ago
parent 8de7d8bc0a
commit cd6e5f5da8

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

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

Loading…
Cancel
Save