Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import top.continew.starter.data.mp.service.IService;
import top.continew.starter.extension.crud.service.BaseService;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -73,6 +74,40 @@ default FileInfo upload(MultipartFile file, String parentPath) throws IOExceptio
*/
FileInfo upload(MultipartFile file, String parentPath, String storageCode) throws IOException;

/**
* 上传到默认存储
*
* @param file 文件信息
* @return 文件信息
* @throws IOException /
*/
default FileInfo upload(File file) throws IOException {
return upload(file, getDefaultParentPath(), null);
}

/**
* 上传到默认存储
*
* @param file 文件信息
* @param parentPath 上级目录
* @return 文件信息
* @throws IOException /
*/
default FileInfo upload(File file, String parentPath) throws IOException {
return upload(file, parentPath, null);
}

/**
* 上传到指定存储
*
* @param file 文件信息
* @param parentPath 上级目录
* @param storageCode 存储编码
* @return 文件信息
* @throws IOException /
*/
FileInfo upload(File file, String parentPath, String storageCode) throws IOException;

/**
* 创建目录
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.extension.crud.service.BaseServiceImpl;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -93,6 +94,19 @@ public void beforeDelete(List<Long> ids) {
public FileInfo upload(MultipartFile file, String parentPath, String storageCode) throws IOException {
// 校验文件格式
String extName = FileNameUtil.extName(file.getOriginalFilename());
return getFileInfo(file, parentPath, storageCode, extName);
}

/**
* 上传文件并返回上传后的文件信息
*
* @param file
* @param parentPath
* @param storageCode
* @param extName
* @return
*/
private FileInfo getFileInfo(Object file, String parentPath, String storageCode, String extName) {
List<String> allExtensions = FileTypeEnum.getAllExtensions();
CheckUtils.throwIf(!allExtensions.contains(extName), "不支持的文件类型,仅支持 {} 格式的文件", String
.join(StringConstants.COMMA, allExtensions));
Expand Down Expand Up @@ -131,6 +145,13 @@ public void finish() {
return uploadPretreatment.upload();
}

@Override
public FileInfo upload(File file, String parentPath, String storageCode) throws IOException {
// 校验文件格式
String extName = FileNameUtil.extName(file.getName());
return getFileInfo(file, parentPath, storageCode, extName);
}

@Override
public Long createDir(FileReq req) {
String parentPath = req.getParentPath();
Expand Down
Loading