mirror of https://github.com/jeecgboot/jeecg-boot
[issue/4672]方法造成的文件被占用,注释掉此方法tomcat就能自动清理掉临时文件 ]
parent
42589cd1dc
commit
ebcddad130
|
@ -1,19 +1,19 @@
|
||||||
package org.jeecg.common.util.filter;
|
package org.jeecg.common.util.filter;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 校验上传文件敏感后缀
|
* @Description: 校验上传文件敏感后缀
|
||||||
* @author: lsq
|
* @author: lsq
|
||||||
* @date: 2021年08月09日 15:29
|
* @date: 2021年08月09日 15:29
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class FileTypeFilter {
|
public class FileTypeFilter {
|
||||||
|
|
||||||
/**文件后缀*/
|
/**文件后缀*/
|
||||||
|
@ -112,8 +112,9 @@ public class FileTypeFilter {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static String getFileType(MultipartFile file) throws Exception {
|
private static String getFileType(MultipartFile file) throws Exception {
|
||||||
|
//update-begin-author:liusq date:20230404 for: [issue/4672]方法造成的文件被占用,注释掉此方法tomcat就能自动清理掉临时文件
|
||||||
String fileExtendName = null;
|
String fileExtendName = null;
|
||||||
InputStream is;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
//is = new FileInputStream(file);
|
//is = new FileInputStream(file);
|
||||||
is = file.getInputStream();
|
is = file.getInputStream();
|
||||||
|
@ -130,17 +131,30 @@ public class FileTypeFilter {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("-----获取到的指定文件类型------"+fileExtendName);
|
||||||
// 如果不是上述类型,则判断扩展名
|
// 如果不是上述类型,则判断扩展名
|
||||||
if (StringUtils.isBlank(fileExtendName)) {
|
if (StringUtils.isBlank(fileExtendName)) {
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
|
// 如果无扩展名,则直接返回空串
|
||||||
|
if (-1 == fileName.indexOf(".")) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// 如果有扩展名,则返回扩展名
|
||||||
return getFileTypeBySuffix(fileName);
|
return getFileTypeBySuffix(fileName);
|
||||||
}
|
}
|
||||||
|
log.info("-----最終的文件类型------"+fileExtendName);
|
||||||
is.close();
|
is.close();
|
||||||
return fileExtendName;
|
return fileExtendName;
|
||||||
} catch (Exception exception) {
|
} catch (Exception e) {
|
||||||
throw new Exception(exception.getMessage(), exception);
|
log.error(e.getMessage(), e);
|
||||||
|
return "";
|
||||||
|
}finally {
|
||||||
|
if (is != null) {
|
||||||
|
is.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//update-end-author:liusq date:20230404 for: [issue/4672]方法造成的文件被占用,注释掉此方法tomcat就能自动清理掉临时文件
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得文件头部字符串
|
* 获得文件头部字符串
|
||||||
|
|
Loading…
Reference in New Issue