From f9ac0ce789b4cb20bd39034225bc3ff8f8032d21 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 3 Aug 2021 16:29:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=E4=B8=8A=E4=BC=A0=E6=8A=A5?= =?UTF-8?q?=E4=BA=8B=E6=96=87=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/OssController.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java index 4914a71cfc..4fc64984c9 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java @@ -22,6 +22,7 @@ import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AliyunGroup; import com.epmet.commons.tools.validator.group.QcloudGroup; import com.epmet.commons.tools.validator.group.QiniuGroup; +import com.epmet.constants.PrivacyType; import com.epmet.dto.UploadDTO; import com.epmet.dto.form.RemoveFileFormDTO; import com.epmet.dto.result.UploadImgResultDTO; @@ -373,4 +374,31 @@ public class OssController { return ossService.uploadImgV2(file, null, customerId); } + /** + * @Description 上传报事文件(目前只有图片) + * @return + * @author wxz + * @date 2021.08.03 16:23 + */ + @PostMapping("upload-resi-event-file") + public Result uploadResiEventFile(@RequestPart(value = "file") MultipartFile file, @RequestParam("customerId") String customerId) { + + // 体积限制 + int sizeMb = 10; + int sizeThreshold = sizeMb * 1024 * 1024; // 大小限制10m + if (file.getSize() > sizeThreshold) { + throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getCode(), + EpmetErrorCode.OPER_UPLOAD_FILE_OVER_SIZE.getMsg().concat(",限制在").concat(String.valueOf(sizeMb)).concat("M以内")); + } + + // 格式限制,只允许png和jpeg + if (!MediaType.IMAGE_PNG_VALUE.equals(file.getContentType()) + && !MediaType.IMAGE_JPEG_VALUE.equals(file.getContentType())) { + throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() + , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); + } + + return ossService.uploadImgV2(file, PrivacyType.EXTERNAL, customerId); + } + }