|
|
@@ -116,26 +116,29 @@ public class FileUploadUtil {
|
|
|
// 这里目前只会说图片的
|
|
|
String contentType = "image/" + suffix;
|
|
|
|
|
|
- ByteArrayInputStream byteArrayInputStream = IoUtil.toStream(b);
|
|
|
-
|
|
|
- long srcSize = b.length;
|
|
|
- double accuracy = getAccuracy(srcSize / 1024);
|
|
|
- try {
|
|
|
- while (b.length > 40L * 1024) {
|
|
|
- ByteArrayInputStream inputStream = new ByteArrayInputStream(b);
|
|
|
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(b.length);
|
|
|
- Thumbnails.of(inputStream)
|
|
|
- .scale(accuracy)
|
|
|
- .outputQuality(accuracy)
|
|
|
- .toOutputStream(outputStream);
|
|
|
- b = outputStream.toByteArray();
|
|
|
+ if ("4".equals(image.getStep())){
|
|
|
+ ByteArrayInputStream byteArrayInputStream = IoUtil.toStream(b);
|
|
|
+
|
|
|
+ long srcSize = b.length;
|
|
|
+ double accuracy = getAccuracy(srcSize / 1024);
|
|
|
+ try {
|
|
|
+ while (b.length > 40L * 1024) {
|
|
|
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(b);
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(b.length);
|
|
|
+ Thumbnails.of(inputStream)
|
|
|
+ .scale(accuracy)
|
|
|
+ .outputQuality(accuracy)
|
|
|
+ .toOutputStream(outputStream);
|
|
|
+ b = outputStream.toByteArray();
|
|
|
+ }
|
|
|
+ log.info("图片原大小={}kb | 压缩后大小={}kb",
|
|
|
+ srcSize / 1024, b.length / 1024);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【图片压缩】msg=图片压缩失败!", e);
|
|
|
}
|
|
|
- log.info("图片原大小={}kb | 压缩后大小={}kb",
|
|
|
- srcSize / 1024, b.length / 1024);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("【图片压缩】msg=图片压缩失败!", e);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
uploadFile(imagePath, contentType, b);
|
|
|
// FileUtils.writeByteArrayToFile(fullPath, b);
|
|
|
return imagePath;
|