|
@@ -36,7 +36,9 @@ import org.springblade.resource.vo.NewBladeFile;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springblade.business.utils.FileUtils;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
@@ -175,8 +177,17 @@ public class OssEndpoint {
|
|
|
@SneakyThrows
|
|
|
@PostMapping("/upload-file")
|
|
|
public synchronized R<NewBladeFile> uploadFile(@RequestParam MultipartFile file){
|
|
|
- //上传原文件
|
|
|
- BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
|
|
|
+ //设置大于3M的文件压缩
|
|
|
+ double targetSize = 3 * 1024 * 1024;
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ //压缩文件大小
|
|
|
+ while (bytes.length > targetSize) {
|
|
|
+ float reduceMultiple = 0.5f;
|
|
|
+ bytes = FileUtils.resizeImage2(bytes, reduceMultiple);
|
|
|
+ }
|
|
|
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
|
|
|
+ //上传文件
|
|
|
+ BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(),inputStream);
|
|
|
|
|
|
//处理PDF文件
|
|
|
NewBladeFile newBladeFile = new NewBladeFile();
|