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.service.file.IHweiYunOBSService;
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.tags.Tag;
import jakarta.annotation.Resource;
@ -40,10 +41,11 @@ public class FileController {
// 优化设置一个合理的缓冲区大小
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桶
@ -94,7 +96,7 @@ public class FileController {
*/
@PostMapping("/upload")
@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);
@ -105,16 +107,19 @@ public class FileController {
// 获取文件的保存路径
String filePath = getFilePath(multipartFile, uploadFileRequest);
// 格式化图片特殊字符
filePath = RegexUtils.encodeUrl(filePath);
// 创建上传目录如果不存在
File file = new File(UPLOAD_DIR + filePath);
if (!file.exists()) {
file.mkdirs(); // 如果路径不存在则创建
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();// 如果路径不存在则创建
}
// 将文件上传到目标位置
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE)) {
bos.write(multipartFile.getBytes());
} catch (IOException e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "文件上传失败");
throw new BusinessException(ErrorCode.OPERATION_ERROR, "文件上传失败,失败原因:" + e.getMessage());
}
return ResultUtils.success(filePath, "上传成功");

View File

@ -39,7 +39,7 @@ springdoc:
server:
port: 9090
port: 9092
servlet:
context-path: /api
@ -53,7 +53,8 @@ mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:
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:
db-config:
logic-delete-field: isDelete #全局逻辑删除的实体字段名