this is 4.2 update
This commit is contained in:
parent
82c8e53514
commit
2b9aa62dfd
|
@ -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, "上传成功");
|
||||
|
|
|
@ -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 #全局逻辑删除的实体字段名
|
||||
|
|
Loading…
Reference in New Issue
Block a user