Browse Source

/oss/file/upload-resi-event-file 图片超过2M的压缩下试试

master
yinzuomei 3 years ago
parent
commit
5336adff31
  1. 8
      epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java
  2. 2
      epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/OssService.java
  3. 4
      epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/impl/OssServiceImpl.java

8
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<UploadImgResultDTO> 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);
}

2
epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/service/OssService.java

@ -31,7 +31,7 @@ public interface OssService extends BaseService<OssEntity> {
Result<UploadImgResultDTO> uploadImg(MultipartFile file, String privacy);
Result<UploadImgResultDTO> compressUploadImg(MultipartFile file, String privacy);
Result<UploadImgResultDTO> compressUploadImg(MultipartFile file, String privacy,long desFileSize);
Result<UploadImgResultDTO> extUpload(MultipartFile file, String fileName, String privacy);

4
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<OssDao, OssEntity> implement
}
@Override
public Result<UploadImgResultDTO> compressUploadImg(MultipartFile file, String privacy) {
public Result<UploadImgResultDTO> compressUploadImg(MultipartFile file, String privacy,long desFileSize) {
if (file.isEmpty()) {
return new Result<UploadImgResultDTO>().error(ModuleErrorCode.UPLOAD_FILE_EMPTY);
}
@ -110,7 +110,7 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> 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);

Loading…
Cancel
Save