|
|
@ -166,17 +166,31 @@ public class OssController { |
|
|
|
|
|
|
|
@PostMapping("uploadFile") |
|
|
|
public Result<String> uploadFile(@RequestBody UploadToOssDTO dto) throws Exception { |
|
|
|
byte[] fileByte = dto.getFileByte(); |
|
|
|
if (null == fileByte || fileByte.length == NumConstant.ZERO) { |
|
|
|
return new Result().error(ModuleErrorCode.UPLOAD_FILE_EMPTY); |
|
|
|
} |
|
|
|
// 图片压缩
|
|
|
|
byte[] imgBytes = CompressImgUtils.commpressPicCycle(fileByte, 110, 0.9); |
|
|
|
//上传文件
|
|
|
|
String extension = FilenameUtils.getExtension(dto.getFileName()); |
|
|
|
String url = OssFactory.build().uploadSuffix(imgBytes, extension); |
|
|
|
if (StringUtils.isNotBlank(dto.getCode())) { |
|
|
|
String name = ItemStateCodeEnum.getValueByCode(dto.getCode()); |
|
|
|
|
|
|
|
// 图片压缩
|
|
|
|
byte[] afterJyBytes = CompressImgUtils.commpressPicCycle(dto.getFileByte(), 1024, 0.5); |
|
|
|
|
|
|
|
return new Result().ok(url); |
|
|
|
//上传文件
|
|
|
|
String extension = FilenameUtils.getExtension(dto.getFileName()); |
|
|
|
String url = OssFactory.build().upload(afterJyBytes, name, extension); |
|
|
|
|
|
|
|
return new Result().ok(url); |
|
|
|
} else { |
|
|
|
|
|
|
|
byte[] fileByte = dto.getFileByte(); |
|
|
|
if (null == fileByte || fileByte.length == NumConstant.ZERO) { |
|
|
|
return new Result().error(ModuleErrorCode.UPLOAD_FILE_EMPTY); |
|
|
|
} |
|
|
|
// 图片压缩
|
|
|
|
byte[] imgBytes = CompressImgUtils.commpressPicCycle(fileByte, 110, 0.9); |
|
|
|
//上传文件
|
|
|
|
String extension = FilenameUtils.getExtension(dto.getFileName()); |
|
|
|
String url = OssFactory.build().uploadSuffix(imgBytes, extension); |
|
|
|
|
|
|
|
return new Result().ok(url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -281,4 +295,32 @@ public class OssController { |
|
|
|
String url = OssFactory.build().upload(afterJyBytes, name, extension); |
|
|
|
return ossService.afterUpload(url, file.getSize()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 图片上传并压缩缩略图 |
|
|
|
* |
|
|
|
* @return void |
|
|
|
* @author lpf |
|
|
|
* @date 2020/03/27 |
|
|
|
*/ |
|
|
|
@PostMapping("uploadImg/{code}") |
|
|
|
@ApiOperation(value = "上传图片") |
|
|
|
public Result<UploadImgAllDTO> uploadImgByCode(@RequestParam("file") MultipartFile file, @PathVariable("code") String code) throws Exception { |
|
|
|
if (file.isEmpty()) { |
|
|
|
return new Result<UploadImgAllDTO>().error(ModuleErrorCode.UPLOAD_FILE_EMPTY); |
|
|
|
} |
|
|
|
String name = ItemStateCodeEnum.getValueByCode(code); |
|
|
|
|
|
|
|
// 图片压缩
|
|
|
|
byte[] afterJyBytes = CompressImgUtils.commpressPicCycle(file.getBytes(), 1024, 0.5); |
|
|
|
|
|
|
|
//上传文件
|
|
|
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
|
|
|
String url = OssFactory.build().upload(afterJyBytes, name, extension); |
|
|
|
UploadImgAllDTO uploadAll = new UploadImgAllDTO(); |
|
|
|
uploadAll.setImgUrl(url); |
|
|
|
uploadAll.setThumbnail(url); |
|
|
|
uploadAll.setFileName(name); |
|
|
|
return new Result<UploadImgAllDTO>().ok(uploadAll); |
|
|
|
} |
|
|
|
} |
|
|
|