Browse Source

1、解决上传文件,文件名称重复bug

rayson 8 months ago
parent
commit
e7fbfb7e68

+ 4 - 2
menduner/menduner-system-biz/src/main/java/com/citu/module/menduner/system/controller/app/common/file/AppFileController.java

@@ -2,6 +2,7 @@ package com.citu.module.menduner.system.controller.app.common.file;
 
 import cn.hutool.core.io.IoUtil;
 import com.citu.framework.common.pojo.CommonResult;
+import com.citu.framework.common.util.io.FileUtils;
 import com.citu.framework.security.core.annotations.PreAuthenticated;
 import com.citu.module.infra.api.file.FileApi;
 import com.citu.module.menduner.common.util.LoginUserContext;
@@ -45,10 +46,11 @@ public class AppFileController {
         MultipartFile file = reqVO.getFile();
         String path = reqVO.getPath();
         if (StringUtils.hasText(path)) {
+            String name = FileUtils.generatePath(IoUtil.readBytes(file.getInputStream()), file.getOriginalFilename());
             if (path.endsWith("/")) {
-                path += file.getOriginalFilename();
+                path += name;
             } else {
-                path += "/" + file.getOriginalFilename();
+                path += "/" + name;
             }
         }