@PostMapping(value = "/upLoadFile")
@ApiOperation(value = "上传文件")
public Result upLoadFile(@RequestParam("file") MultipartFile file) {
try {
log.info("上传文件大小:" + file.getSize() / 1024 + "kb;文件名称:" + file.getOriginalFilename());
ByteArrayOutputStream byteArrayOutputStreamut = new ByteArrayOutputStream();
Thumbnails.of(file.getInputStream())
.scale(0.08f)//放大还是缩小
.outputQuality(0.5f)//图片质量
.toOutputStream(byteArrayOutputStreamut);
log.info("压缩后文件大小:" + byteArrayOutputStreamut.toByteArray().length / 1024 + "kb;");
//下面是上传到阿里云。。。可以忽略
return Result.success(uploadFile.uploadAndReturnUrl(file.getInputStream(), file.getOriginalFilename()));
} catch (IOException e) {
e.printStackTrace();
}
return Result.fail("上传文件失败");
}