文件上传方案修改
This commit is contained in:
		| @@ -6,7 +6,6 @@ import cn.hutool.core.io.IoUtil; | ||||
| import cn.hutool.core.util.IdUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.hutool.core.util.URLUtil; | ||||
| import com.jeelowcode.framework.utils.tool.StringUtil; | ||||
| import com.jeelowcode.service.infra.controller.vo.file.*; | ||||
| import com.jeelowcode.service.infra.entity.FileDO; | ||||
| import com.jeelowcode.service.infra.service.IFileService; | ||||
| @@ -24,7 +23,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.security.access.prepost.PreAuthorize; | ||||
| import org.springframework.util.StringUtils; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
| @@ -34,6 +32,8 @@ import javax.annotation.security.PermitAll; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.validation.Valid; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.format.DateTimeFormatter; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| @@ -69,7 +69,7 @@ public class FileController { | ||||
|         String path = publicPath + fileName; | ||||
|  | ||||
|         fileName = fileService.getUniqueFileName(fileName, path); | ||||
|         path = publicPath + fileName; | ||||
|         path = publicPath + IdUtil.simpleUUID() + (StrUtil.isEmpty(FileUtil.extName(fileName)) ? "" : ("." + FileUtil.extName(fileName))); | ||||
|  | ||||
|         return success(fileService.createFile(fileName, path, IoUtil.readBytes(file.getInputStream()))); | ||||
|     } | ||||
| @@ -88,15 +88,16 @@ public class FileController { | ||||
|             tenantId = loginUser.getTenantId(); | ||||
|             userId = loginUser.getId(); | ||||
|         } | ||||
|         //根据天来分类 | ||||
|         String today = DateUtil.today(); | ||||
|         String publicPath = "upload/" + tenantId + "/" + today + "/" + userId + "/"; //upload/租户id/20240720/用户id/aa.jpg | ||||
|  | ||||
|         fileName = StringUtil.randomUUID()+"."+fileName.substring(fileName.lastIndexOf(".")+1);;////fileService.getUniqueFileName(fileName, path); | ||||
|         //每个文件放一个文件夹,防止乱码后找不到正确文件 | ||||
|         LocalDateTime now = LocalDateTime.now(); | ||||
|         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HHmmssSSS"); | ||||
|         String timeString = now.format(formatter); | ||||
|         String publicPath = "upload/" + tenantId + "/" + userId + "/" + timeString + "/"; | ||||
|         String path = publicPath + fileName; | ||||
|  | ||||
|         fileName = fileService.getUniqueFileName(fileName, path); | ||||
|         // 解决信创环境下文件名中文乱码导致附件错乱的问题 | ||||
|         path = publicPath + fileName; | ||||
|         //path = publicPath + IdUtil.simpleUUID() + (StrUtil.isEmpty(FileUtil.extName(fileName)) ? "" : ("." + FileUtil.extName(fileName))); | ||||
|  | ||||
|         String fileUrl = fileService.createFile(fileName, path, IoUtil.readBytes(file.getInputStream())); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user