文件上传,是图片时再压缩
This commit is contained in:
parent
aefc1418ec
commit
03bdc7c3cc
|
@ -132,6 +132,17 @@ public class FileUploadUtils
|
||||||
//file.transferTo(desc);
|
//file.transferTo(desc);
|
||||||
IoUtil.close(out);
|
IoUtil.close(out);
|
||||||
String pathFileName = getPathFileName(baseDir, fileName);
|
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 {
|
// try {
|
||||||
// File input = new File(baseDir+"/"+fileName);
|
// File input = new File(baseDir+"/"+fileName);
|
||||||
// BufferedImage image = ImageIO.read(input);
|
// BufferedImage image = ImageIO.read(input);
|
||||||
|
@ -151,6 +162,8 @@ public class FileUploadUtils
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// System.out.println("压缩失败:" + e.getMessage());
|
// System.out.println("压缩失败:" + e.getMessage());
|
||||||
// }
|
// }
|
||||||
|
//如果是图片则压缩
|
||||||
|
if(isImg){
|
||||||
try {
|
try {
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
|
@ -167,6 +180,7 @@ public class FileUploadUtils
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return pathFileName;
|
return pathFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue