deason 1 year ago
parent
commit
2b9cf3eb77

+ 3 - 6
examcloud-support/src/main/java/cn/com/qmth/examcloud/support/fss/FssHelper.java

@@ -2,7 +2,6 @@ package cn.com.qmth.examcloud.support.fss;
 
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,6 +66,7 @@ public class FssHelper {
     public static String getFileName(String filePath) {
         if (filePath != null) {
             filePath = filePath.replace("\\", "/");
+
             int index = filePath.lastIndexOf("/");
             if (index >= 0) {
                 return filePath.substring(index + 1);
@@ -80,10 +80,6 @@ public class FssHelper {
      * 获取文件MD5值
      */
     public static String getFileMD5(byte[] fileBytes) {
-        if (ArrayUtils.isEmpty(fileBytes)) {
-            throw new RuntimeException("文件大小不能为空!");
-        }
-
         return DigestUtils.md5Hex(fileBytes);
     }
 
@@ -94,8 +90,9 @@ public class FssHelper {
         if (file == null) {
             throw new RuntimeException("文件不能为空!");
         }
+
         if (!file.isFile()) {
-            throw new RuntimeException("文件类型不能正确!");
+            throw new RuntimeException("文件类型错误!");
         }
 
         try (FileInputStream fis = new FileInputStream(file);) {

+ 7 - 0
examcloud-support/src/main/java/cn/com/qmth/examcloud/support/fss/impl/AliyunOssService.java

@@ -39,6 +39,13 @@ public class AliyunOssService implements FssService {
 
     @Override
     public FileInfo writeFile(String filePath, File file, String md5) {
+        if (file == null) {
+            throw new StatusException("文件不能为空!");
+        }
+        if (!file.isFile()) {
+            throw new StatusException("文件类型错误!");
+        }
+
         if (StringUtils.isNotEmpty(md5)) {
             String realMd5 = FssHelper.getFileMD5(file);
 

+ 7 - 0
examcloud-support/src/main/java/cn/com/qmth/examcloud/support/fss/impl/TencentCosService.java

@@ -30,6 +30,13 @@ public class TencentCosService implements FssService {
 
     @Override
     public FileInfo writeFile(String filePath, File file, String md5) {
+        if (file == null) {
+            throw new StatusException("文件不能为空!");
+        }
+        if (!file.isFile()) {
+            throw new StatusException("文件类型错误!");
+        }
+
         if (StringUtils.isNotEmpty(md5)) {
             String realMd5 = FssHelper.getFileMD5(file);
             if (!md5.equals(realMd5)) {