Commit 1f15439d authored by 董天德's avatar 董天德

Merge remote-tracking branch 'origin/dev_20230209_xuhd'

parents 68dd0cdd 66a5d5dc
......@@ -31,6 +31,8 @@ public enum ResultCode implements IResultCode, Serializable {
TOKEN_INVALID_OR_EXPIRED("A0230", "token无效或已过期"),
// 请求参数错误,参数校验不通过
REQUEST_PARAM_ERROR("Q0001", "请求参数错误"),
//文件类型不匹配
FILE_TYPE_ERROR("F0001", "文件类型不支持"),
// 请求参数错误,参数校验不通过
SRV_ORGAN_NOT_QUERY("S0001", "未查询到数据"),
/**
......
......@@ -4,11 +4,14 @@ import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Data
@ConfigurationProperties(prefix = "file.upload")
public class FileUploadConfig {
private String path;
private List<String> type;
}
......@@ -38,7 +38,16 @@ public class FileUploadController {
if (null == uploadType || null == file) {
return Result.failed(ResultCode.REQUEST_PARAM_ERROR);
}
//过滤上传资料类型
String originalFilename = file.getOriginalFilename();
//文件类型
String fileType = originalFilename.substring(file.getOriginalFilename().lastIndexOf("."));
List<String> fileTypes = fileUploadConfig.getType();
log.info("支持图片类型:" + fileTypes+",上传的图片类型:"+fileType);
if(!fileTypes.contains(fileType)){
log.info("上传文件错误");
return Result.failed(ResultCode.FILE_TYPE_ERROR);
}
String realPath = FileUtils.uploadFile(file, fileUploadConfig.getPath());
log.info("文件上传成功:{}", realPath);
Long attachId = attachService.saveFileInfo(originalFilename, realPath, uploadType);
......
......@@ -34,4 +34,11 @@ mybatis-plus:
file:
upload:
path: E:/workspace/upload
\ No newline at end of file
path: E:/workspace/upload
type:
- .JPG
- .JPEG
- .jpg
- .jpeg
- .png
- .PNG
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment