From 5336adff31937d8215c46ce2b918ff35d711aa18 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Wed, 6 Jul 2022 14:22:08 +0800 Subject: [PATCH] =?UTF-8?q?/oss/file/upload-resi-event-file=20=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=B6=85=E8=BF=872M=E7=9A=84=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E4=B8=8B=E8=AF=95=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/controller/OssController.java | 8 ++++++-- .../src/main/java/com/epmet/service/OssService.java | 2 +- .../main/java/com/epmet/service/impl/OssServiceImpl.java | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) 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 b265308eaf..e593cb7a95 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 @@ -158,7 +158,7 @@ public class OssController { */ @PostMapping("compressuploadimg") public Result compressUploadImg(@RequestParam("file") MultipartFile file) { - return ossService.compressUploadImg(file, null); + return ossService.compressUploadImg(file, null,200L); } @PostMapping("uploadwximg") @@ -410,7 +410,11 @@ public class OssController { throw new RenException(EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getCode() , EpmetErrorCode.OPER_UPLOAD_FILE_TYPE_ERROR.getMsg()); } - + //如果图片大于2M压缩一下 + int compressSize = 2 * 1024 * 1024; + if(file.getSize()>compressSize){ + return ossService.compressUploadImg(file, null,2 * 1024); + } return ossService.uploadImgV2(file, PrivacyType.EXTERNAL, customerId); } diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/OssService.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/OssService.java index d9e210c006..531cf986fb 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/OssService.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/OssService.java @@ -31,7 +31,7 @@ public interface OssService extends BaseService { Result uploadImg(MultipartFile file, String privacy); - Result compressUploadImg(MultipartFile file, String privacy); + Result compressUploadImg(MultipartFile file, String privacy,long desFileSize); Result extUpload(MultipartFile file, String fileName, String privacy); diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java index 40d5d7b492..d55751762c 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java @@ -101,7 +101,7 @@ public class OssServiceImpl extends BaseServiceImpl implement } @Override - public Result compressUploadImg(MultipartFile file, String privacy) { + public Result compressUploadImg(MultipartFile file, String privacy,long desFileSize) { if (file.isEmpty()) { return new Result().error(ModuleErrorCode.UPLOAD_FILE_EMPTY); } @@ -110,7 +110,7 @@ public class OssServiceImpl extends BaseServiceImpl implement String url = null; String ossDomain = null; try { - byte[] fileBytes = compressPicCycle(file.getBytes(),200L,0.3); + byte[] fileBytes = compressPicCycle(file.getBytes(),desFileSize,0.3); AbstractCloudStorageService storageService = OssFactory.build(); url = storageService.uploadSuffix(fileBytes, extension, privacy); ossDomain = storageService.getOssDomain(privacy);