文件上传,是图片时再压缩
This commit is contained in:
parent
aefc1418ec
commit
03bdc7c3cc
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue