From ebcddad130a362f8bebe07b269cbb48374613aa8 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Wed, 5 Apr 2023 11:45:10 +0800 Subject: [PATCH] =?UTF-8?q?[issue/4672]=E6=96=B9=E6=B3=95=E9=80=A0?= =?UTF-8?q?=E6=88=90=E7=9A=84=E6=96=87=E4=BB=B6=E8=A2=AB=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=B3=A8=E9=87=8A=E6=8E=89=E6=AD=A4=E6=96=B9=E6=B3=95?= =?UTF-8?q?tomcat=E5=B0=B1=E8=83=BD=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=8E=89=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/filter/FileTypeFilter.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/filter/FileTypeFilter.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/filter/FileTypeFilter.java index 198e8fd4..cc0ce9d7 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/filter/FileTypeFilter.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/filter/FileTypeFilter.java @@ -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就能自动清理掉临时文件 } /**