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);