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;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @Description: 校验上传文件敏感后缀
|
||||
* @author: lsq
|
||||
* @date: 2021年08月09日 15:29
|
||||
*/
|
||||
@Slf4j
|
||||
public class FileTypeFilter {
|
||||
|
||||
/**文件后缀*/
|
||||
|
@ -112,8 +112,9 @@ public class FileTypeFilter {
|
|||
*/
|
||||
|
||||
private static String getFileType(MultipartFile file) throws Exception {
|
||||
//update-begin-author:liusq date:20230404 for: [issue/4672]方法造成的文件被占用,注释掉此方法tomcat就能自动清理掉临时文件
|
||||
String fileExtendName = null;
|
||||
InputStream is;
|
||||
InputStream is = null;
|
||||
try {
|
||||
//is = new FileInputStream(file);
|
||||
is = file.getInputStream();
|
||||
|
@ -130,16 +131,29 @@ public class FileTypeFilter {
|
|||
break;
|
||||
}
|
||||
}
|
||||
log.info("-----获取到的指定文件类型------"+fileExtendName);
|
||||
// 如果不是上述类型,则判断扩展名
|
||||
if (StringUtils.isBlank(fileExtendName)) {
|
||||
String fileName = file.getOriginalFilename();
|
||||
// 如果无扩展名,则直接返回空串
|
||||
if (-1 == fileName.indexOf(".")) {
|
||||
return "";
|
||||
}
|
||||
// 如果有扩展名,则返回扩展名
|
||||
return getFileTypeBySuffix(fileName);
|
||||
}
|
||||
log.info("-----最終的文件类型------"+fileExtendName);
|
||||
is.close();
|
||||
return fileExtendName;
|
||||
} catch (Exception exception) {
|
||||
throw new Exception(exception.getMessage(), exception);
|
||||
} catch (Exception e) {
|
||||
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