文件上传,是图片时再压缩

This commit is contained in:
曹磊 2024-07-18 14:07:32 +08:00
parent aefc1418ec
commit 03bdc7c3cc
1 changed files with 28 additions and 14 deletions

View File

@ -132,6 +132,17 @@ public class FileUploadUtils
//file.transferTo(desc);
IoUtil.close(out);
String pathFileName = getPathFileName(baseDir, fileName);
String extension = getExtension(file);
String[] imgExtension = {"bmp", "gif", "jpg", "jpeg", "png"};
boolean isImg = false;
for (String str : imgExtension)
{
if (str.equalsIgnoreCase(extension))
{
isImg = true;
}
}
// try {
// File input = new File(baseDir+"/"+fileName);
// BufferedImage image = ImageIO.read(input);
@ -151,6 +162,8 @@ public class FileUploadUtils
// } catch (Exception e) {
// System.out.println("压缩失败:" + e.getMessage());
// }
//如果是图片则压缩
if(isImg){
try {
Date date = new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
@ -167,6 +180,7 @@ public class FileUploadUtils
} catch (IOException e) {
e.printStackTrace();
}
}
return pathFileName;
}