this is 4.2 update

This commit is contained in:
chen-xin-zhi 2025-04-04 14:26:02 +08:00
parent 82c8e53514
commit 2b9aa62dfd
2 changed files with 15 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import com.cultural.heritage.model.dto.file.UploadFileRequest;
import com.cultural.heritage.model.enums.FileUploadBizEnum; import com.cultural.heritage.model.enums.FileUploadBizEnum;
import com.cultural.heritage.service.file.IHweiYunOBSService; import com.cultural.heritage.service.file.IHweiYunOBSService;
import com.cultural.heritage.service.user.UserService; import com.cultural.heritage.service.user.UserService;
import com.cultural.heritage.utils.RegexUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -40,10 +41,11 @@ public class FileController {
// 优化设置一个合理的缓冲区大小 // 优化设置一个合理的缓冲区大小
private static final int BUFFER_SIZE = 8192; // 8 KB private static final int BUFFER_SIZE = 8192; // 8 KB
// 上传文件的存储目录 // 上传文件的服务器存储目录
private static final String UPLOAD_DIR = "/www/wwwroot/fileUpload/"; // 请替换为实际路径 private static final String UPLOAD_DIR = "/www/wwwroot/fileUpload/";
// // 上传文件的本地存储目录
// private static final String UPLOAD_DIR = "D:/uploads/fileUpload/";
// /** // /**
// * Web端文件上传obs桶 // * Web端文件上传obs桶
@ -94,7 +96,7 @@ public class FileController {
*/ */
@PostMapping("/upload") @PostMapping("/upload")
@Operation(summary = "Web端文件上传服务器", description = "参数文件对象multipartFile), 业务类型(biz)权限管理员方法名uploadFile") @Operation(summary = "Web端文件上传服务器", description = "参数文件对象multipartFile), 业务类型(biz)权限管理员方法名uploadFile")
public BaseResponse<String> uploadFileToServe(@RequestParam("file") MultipartFile multipartFile, @RequestBody UploadFileRequest uploadFileRequest, HttpServletRequest request) throws IOException { public BaseResponse<String> uploadFileToServe(@RequestPart("file") MultipartFile multipartFile, UploadFileRequest uploadFileRequest, HttpServletRequest request) throws IOException {
// 校验用户是否登录 // 校验用户是否登录
userService.getLoginUser(request); userService.getLoginUser(request);
@ -105,16 +107,19 @@ public class FileController {
// 获取文件的保存路径 // 获取文件的保存路径
String filePath = getFilePath(multipartFile, uploadFileRequest); String filePath = getFilePath(multipartFile, uploadFileRequest);
// 格式化图片特殊字符
filePath = RegexUtils.encodeUrl(filePath);
// 创建上传目录如果不存在 // 创建上传目录如果不存在
File file = new File(UPLOAD_DIR + filePath); File file = new File(UPLOAD_DIR + filePath);
if (!file.exists()) { if (!file.getParentFile().exists()) {
file.mkdirs(); // 如果路径不存在则创建 file.getParentFile().mkdirs();// 如果路径不存在则创建
} }
// 将文件上传到目标位置 // 将文件上传到目标位置
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE)) { try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE)) {
bos.write(multipartFile.getBytes()); bos.write(multipartFile.getBytes());
} catch (IOException e) { } catch (IOException e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "文件上传失败"); throw new BusinessException(ErrorCode.OPERATION_ERROR, "文件上传失败,失败原因:" + e.getMessage());
} }
return ResultUtils.success(filePath, "上传成功"); return ResultUtils.success(filePath, "上传成功");

View File

@ -39,7 +39,7 @@ springdoc:
server: server:
port: 9090 port: 9092
servlet: servlet:
context-path: /api context-path: /api
@ -53,7 +53,8 @@ mybatis-plus:
mapper-locations: classpath:mapper/*.xml mapper-locations: classpath:mapper/*.xml
configuration: configuration:
map-underscore-to-camel-case: false map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
global-config: global-config:
db-config: db-config:
logic-delete-field: isDelete #全局逻辑删除的实体字段名 logic-delete-field: isDelete #全局逻辑删除的实体字段名