给文件上传接口增加文件名称上传的参数,非必填

This commit is contained in:
季圣华
2022-12-05 23:57:45 +08:00
parent 1171ae18f2
commit a317a91261

View File

@@ -128,6 +128,7 @@ public class SystemConfigController {
try { try {
String savePath = ""; String savePath = "";
String bizPath = request.getParameter("biz"); String bizPath = request.getParameter("biz");
String name = request.getParameter("name");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象 MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
if(StringUtil.isEmpty(bizPath)){ if(StringUtil.isEmpty(bizPath)){
@@ -136,7 +137,7 @@ public class SystemConfigController {
String token = request.getHeader("X-Access-Token"); String token = request.getHeader("X-Access-Token");
Long tenantId = Tools.getTenantIdByToken(token); Long tenantId = Tools.getTenantIdByToken(token);
bizPath = bizPath + File.separator + tenantId; bizPath = bizPath + File.separator + tenantId;
savePath = this.uploadLocal(file,bizPath); savePath = this.uploadLocal(file, bizPath, name);
if(StringUtil.isNotEmpty(savePath)){ if(StringUtil.isNotEmpty(savePath)){
res.code = 200; res.code = 200;
res.data = savePath; res.data = savePath;
@@ -158,7 +159,7 @@ public class SystemConfigController {
* @param bizPath 自定义路径 * @param bizPath 自定义路径
* @return * @return
*/ */
private String uploadLocal(MultipartFile mf,String bizPath){ private String uploadLocal(MultipartFile mf,String bizPath,String name){
try { try {
String ctxPath = filePath; String ctxPath = filePath;
String fileName = null; String fileName = null;
@@ -169,7 +170,11 @@ public class SystemConfigController {
String orgName = mf.getOriginalFilename();// 获取文件名 String orgName = mf.getOriginalFilename();// 获取文件名
orgName = FileUtils.getFileName(orgName); orgName = FileUtils.getFileName(orgName);
if(orgName.indexOf(".")!=-1){ if(orgName.indexOf(".")!=-1){
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf(".")); if(StringUtil.isNotEmpty(name)) {
fileName = name.substring(0, name.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
} else {
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
}
}else{ }else{
fileName = orgName+ "_" + System.currentTimeMillis(); fileName = orgName+ "_" + System.currentTimeMillis();
} }