feat(文档拆分): 增加图片校验
This commit is contained in:
+27
-2
@@ -1490,6 +1490,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
try {
|
||||
// String paths = splitUrl+imageName;
|
||||
// MinioUtil.uploadByte(bytev, filepathandname);
|
||||
imgCheck(multipartFile);
|
||||
String upload = ObsBootUtil.upload(multipartFile, "temp");
|
||||
OSSFile ossFile = new OSSFile();
|
||||
ossFile.setId(String.valueOf(SnowflakeUtils.snowflake()));
|
||||
@@ -1556,6 +1557,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
try {
|
||||
// String paths = splitUrl+imageName;
|
||||
// MinioUtil.uploadByte(bytev, filepathandname);
|
||||
imgCheck(multipartFile);
|
||||
String upload = ObsBootUtil.upload(multipartFile, "temp");
|
||||
OSSFile ossFile = new OSSFile();
|
||||
ossFile.setId(String.valueOf(SnowflakeUtils.snowflake()));
|
||||
@@ -1618,6 +1620,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
try {
|
||||
// String paths = splitUrl+imageName;
|
||||
// MinioUtil.uploadByte(bytev, filepathandname);
|
||||
imgCheck(multipartFile);
|
||||
String upload = ObsBootUtil.upload(multipartFile, "temp");
|
||||
OSSFile ossFile = new OSSFile();
|
||||
ossFile.setId(String.valueOf(SnowflakeUtils.snowflake()));
|
||||
@@ -4484,6 +4487,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
// bizPath = "";
|
||||
// }
|
||||
}
|
||||
imgCheck(file);
|
||||
// OSSFile oSSFile = ossFileService.uploadLocalForSplit(file, bizPath,state,cut);
|
||||
String upload = ObsBootUtil.upload(file, "temp");
|
||||
if (oConvertUtils.isNotEmpty(upload)) {
|
||||
@@ -4499,9 +4503,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
result.setResult(ossFile);
|
||||
result.setSuccess(true);
|
||||
} else {
|
||||
if("cut".equals(LanguageEnum.CN.getValue())){
|
||||
if(LanguageEnum.CN.equals(MessageUtils.getLanguage())) {
|
||||
result.setMessage("上传失败!");
|
||||
}else{
|
||||
}else {
|
||||
result.setMessage("fail to upload!");
|
||||
}
|
||||
result.setSuccess(false);
|
||||
@@ -4509,4 +4513,25 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
return result;
|
||||
}
|
||||
|
||||
private void imgCheck(MultipartFile file) {
|
||||
// 格式校验
|
||||
String orgName = file.getOriginalFilename();
|
||||
String fileType = orgName.substring(orgName.lastIndexOf(".")).toLowerCase();
|
||||
List<String> list = Arrays.asList(".jpg", ".jpeg", ".png");
|
||||
if (!list.contains(fileType)){
|
||||
if(LanguageEnum.CN.equals(MessageUtils.getLanguage())) {
|
||||
throw new JeroBootException("只能上传: jpg、jpeg、png类型!");
|
||||
}else{
|
||||
throw new JeroBootException("Only jpg, jpeg, png can be uploaded!");
|
||||
}
|
||||
}
|
||||
// 上传文件不超过20mb
|
||||
if (file.getSize() > 20 * 1024 * 1024) {
|
||||
if(LanguageEnum.CN.equals(MessageUtils.getLanguage())) {
|
||||
throw new JeroBootException("上传文件大小不能超过20MB!");
|
||||
}else {
|
||||
throw new JeroBootException("Upload file size cannot exceed 20MB!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user