文件上传更改

This commit is contained in:
XaoLi717 2024-08-08 11:38:02 +08:00
parent 6339de90f9
commit 34632c3e03
10 changed files with 28 additions and 16 deletions

View File

@ -31,7 +31,8 @@ public class KnowledgePageReqVO extends PageParam {
private String status;
@Schema(description = "文件路径")
private String filePath;
// private String filePath;
private String[] filePath;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@ -54,7 +54,8 @@ public class KnowledgeRespVO {
@Schema(description = "文件路径")
@ExcelProperty("文件路径")
private String filePath;
// private String filePath;
private String[] filePath;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")

View File

@ -40,7 +40,7 @@ public class KnowledgeSaveReqVO {
@Schema(description = "文件路径")
private String[] filePath;
// private List<JSONObject> filePath;
// private List<String> filePath;
// private List<String> filePath;
@Schema(description = "评论列表")

View File

@ -13,7 +13,7 @@ public interface FileApi {
* @param content 文件内容
* @return 文件路径
*/
default String createFile(byte[] content) {
default String[] createFile(byte[] content) {
return createFile(null, null, content);
}
@ -24,7 +24,7 @@ public interface FileApi {
* @param content 文件内容
* @return 文件路径
*/
default String createFile(String path, byte[] content) {
default String[] createFile(String path, byte[] content) {
return createFile(null, path, content);
}
@ -36,6 +36,6 @@ public interface FileApi {
* @param content 文件内容
* @return 文件路径
*/
String createFile(String name, String path, byte[] content);
String[] createFile(String name, String path, byte[] content);
}

View File

@ -19,7 +19,7 @@ public class FileApiImpl implements FileApi {
private FileService fileService;
@Override
public String createFile(String name, String path, byte[] content) {
public String[] createFile(String name, String path, byte[] content) {
return fileService.createFile(name, path, content);
}

View File

@ -40,7 +40,7 @@ public class FileController {
@PostMapping("/upload")
@Operation(summary = "上传文件", description = "模式一:后端上传文件")
public CommonResult<String> uploadFile(FileUploadReqVO uploadReqVO) throws Exception {
public CommonResult<String[]> uploadFile(FileUploadReqVO uploadReqVO) throws Exception {
MultipartFile file = uploadReqVO.getFile();
String path = uploadReqVO.getPath();
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));

View File

@ -29,7 +29,7 @@ public class AppFileController {
@PostMapping("/upload")
@Operation(summary = "上传文件")
public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
public CommonResult<String[]> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
MultipartFile file = uploadReqVO.getFile();
String path = uploadReqVO.getPath();
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));

View File

@ -29,7 +29,7 @@ public interface FileService {
* @param content 文件内容
* @return 文件路径
*/
String createFile(String name, String path, byte[] content);
String[] createFile(String name, String path, byte[] content);
/**
* 创建文件

View File

@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
@ -42,7 +43,7 @@ public class FileServiceImpl implements FileService {
@Override
@SneakyThrows
public String createFile(String name, String path, byte[] content) {
public String[] createFile(String name, String path, byte[] content) {
// 计算默认的 path
String type = FileTypeUtils.getMineType(content, name);
if (StrUtil.isEmpty(path)) {
@ -67,7 +68,16 @@ public class FileServiceImpl implements FileService {
file.setType(type);
file.setSize(content.length);
fileMapper.insert(file);
return url;
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("name",name);
// jsonObject.put("url",url);
String[] liss = new String[2];
System.out.println(name);
System.out.println(url);
liss[0] = name;
liss[1] = url;
System.out.println(Arrays.toString(liss));
return liss;
}
@Override

View File

@ -179,7 +179,7 @@ public class AdminUserServiceImpl implements AdminUserService {
public String updateUserAvatar(Long id, InputStream avatarFile) {
validateUserExists(id);
// 存储文件
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
String avatar = String.valueOf(fileApi.createFile(IoUtil.readBytes(avatarFile)));
// 更新路径
AdminUserDO sysUserDO = new AdminUserDO();
sysUserDO.setId(id);