完成了文件上传

This commit is contained in:
chen-xin-zhi 2024-10-31 19:26:55 +08:00
parent 8dcf105e05
commit 19368e1438

View File

@ -59,7 +59,7 @@ public class FileController {
//文件目录根据业务用户来划分 //文件目录根据业务用户来划分
String uuid = RandomStringUtils.randomAlphabetic(8); String uuid = RandomStringUtils.randomAlphabetic(8);
String filename = uuid + "-" + multipartFile.getOriginalFilename(); String filename = uuid + "-" + multipartFile.getOriginalFilename();
String filepath = String.format("/%s/%s", fileUploadBizEnum.getValue(), filename); String filepath = String.format("/%s/%s/%s", fileUploadBizEnum.getValue(), 0, filename);
// 判断目录是否存在 // 判断目录是否存在
File file = new File(FileConstant.SERVER_UPLOAD_DIR, filepath); File file = new File(FileConstant.SERVER_UPLOAD_DIR, filepath);
@ -71,8 +71,8 @@ public class FileController {
} }
} }
//返回可访问地址 //返回可访问地址
String test = iHweiYunOBSService.fileUpload(multipartFile, "feiyi" + filepath); String url = iHweiYunOBSService.fileUpload(multipartFile, "feiyi" + filepath);
return ResultUtils.success(test); return ResultUtils.success(url);
} }
@ -93,8 +93,21 @@ public class FileController {
} }
// 文件目录根据业务用户来划分 // 文件目录根据业务用户来划分
String uuid = RandomStringUtils.randomAlphabetic(8); String uuid = RandomStringUtils.randomAlphabetic(8);
String s = uuid + "-" + multipartFile.getOriginalFilename(); String filename = uuid + "-" + multipartFile.getOriginalFilename();
return null; String filepath = String.format("/%s/%s/%s", fileUploadBizEnum.getValue(), loginUser.getId(), filename);
// 判断目录是否存在
File file = new File(FileConstant.SERVER_UPLOAD_DIR, filepath);
if (!file.exists()) {
// 创建目录
boolean mkdirs = file.mkdirs();
if (!mkdirs) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "创建目录失败");
}
}
//返回可访问地址
String url = iHweiYunOBSService.fileUpload(multipartFile, "feiyi" + filepath);
return ResultUtils.success(url);
} }