优化上传文件类型过滤的方法

This commit is contained in:
wkeyuan 2023-04-28 15:04:24 +08:00
parent e9f328b936
commit ad7d4d8927
2 changed files with 11 additions and 3 deletions

View File

@ -48,7 +48,6 @@ public class StorageManager {
public static State saveFileByInputStream(InputStream is, String path,
long maxSize) {
System.out.println("saveFileByInputStream");
BaseState validateState = isUserUpFileType(is,path.substring(path.lastIndexOf(".")));
if(!validateState.isSuccess()) return validateState;
State state = new BaseState(false, AppInfo.IO_ERROR);

View File

@ -26,8 +26,17 @@ public class FileMagicUtils {
//根据文件获取对应的文件类型
public static FileMagic getFileMagic(File inp, String fileSuffix) throws Exception {
FileInputStream fis = new FileInputStream(inp);
return getFileMagic(fis,fileSuffix);
FileMagic fileMagic = null;
FileInputStream fis = null;
try{
fis = new FileInputStream(inp);
fileMagic = getFileMagic(fis,fileSuffix);
}catch (Exception e){
e.printStackTrace();
}finally {
if (fis!=null) fis.close();
}
return fileMagic;
}
//切换到使用最新的tika验测