|
@ -205,25 +205,43 @@ public class OssController { |
|
|
return ossService.uploadImg(file, null); |
|
|
return ossService.uploadImg(file, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* desc: 党建声音模块 上传图片(2M)或附件(5M) |
|
|
|
|
|
* |
|
|
|
|
|
* @param file |
|
|
|
|
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.UploadImgResultDTO> |
|
|
|
|
|
* @author LiuJanJun |
|
|
|
|
|
* @date 2021/3/29 4:56 下午 |
|
|
|
|
|
*/ |
|
|
@PostMapping("article/upload") |
|
|
@PostMapping("article/upload") |
|
|
public Result<UploadImgResultDTO> uploadArticleImg(@RequestParam("file") MultipartFile file) { |
|
|
public Result<UploadImgResultDTO> uploadArticleImg(@RequestParam("file") MultipartFile file) { |
|
|
|
|
|
|
|
|
// 校验文件类型
|
|
|
// 校验文件类型 图片或pdf
|
|
|
if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType()) && !MediaType.IMAGE_JPEG_VALUE.equals(file.getContentType()) |
|
|
if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType()) |
|
|
&& !ModuleConstant.FILE_CONTENT_TYPE_JPG.equals(file.getContentType()) ) { |
|
|
&& !MediaType.IMAGE_JPEG_VALUE.equals(file.getContentType()) |
|
|
log.error("uploadArticleImg file type:{} is not support 2 upload",file.getContentType() == null? null:file.getContentType()); |
|
|
&& !ModuleConstant.FILE_CONTENT_TYPE_JPG.equals(file.getContentType()) |
|
|
|
|
|
&& !ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())) { |
|
|
|
|
|
log.error("uploadArticleImg file type:{} is not support 2 upload", file.getContentType()); |
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() |
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() |
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); |
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); |
|
|
} |
|
|
} |
|
|
|
|
|
if (ModuleConstant.FILE_CONTENT_TYPE_PDF.equals(file.getContentType())) { |
|
|
// 校验文件体积,不超过2m
|
|
|
// 校验文件体积,不超过2m
|
|
|
long maxSize = 2 * 1024 * 1024; |
|
|
long maxSize = 5 * 1024 * 1024; |
|
|
long size = file.getSize(); |
|
|
long size = file.getSize(); |
|
|
if (size > maxSize) { |
|
|
if (size > maxSize) { |
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 校验文件体积,不超过2m
|
|
|
|
|
|
long maxSize = 2 * 1024 * 1024; |
|
|
|
|
|
long size = file.getSize(); |
|
|
|
|
|
if (size > maxSize) { |
|
|
|
|
|
throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode() |
|
|
|
|
|
, EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ossService.uploadImg(file, null); |
|
|
return ossService.uploadImg(file, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|