Ver código fonte

增加老师端上传时候文件类型部分限制

Pq 2 anos atrás
pai
commit
b124e06085

+ 16 - 3
BaseLibrary/src/main/java/com/cooleshow/base/utils/FileUtils.java

@@ -20,6 +20,8 @@ import android.util.Log;
 
 import com.luck.picture.lib.tools.BitmapUtils;
 
+import org.w3c.dom.Text;
+
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -1749,21 +1751,32 @@ public final class FileUtils {
         return compressPath;
     }
 
-    public static boolean isMatchTargetFileType(String targetType,String filePath){
+    public static boolean isMatchTargetFileType(String targetType, String filePath) {
         try {
-            if(TextUtils.isEmpty(targetType)){
+            if (TextUtils.isEmpty(targetType)) {
+                Log.i("FileUtils", "targetType is null");
                 return true;
             }
             File file = new File(filePath);
             if (!file.exists()) {
+                Log.i("FileUtils", "file is not exist");
                 return false;
             }
             int lastDot = file.getName().lastIndexOf(".");
             if (lastDot < 0) {
+                Log.i("FileUtils", "lastDot is 0 isEmpty filetype");
                 return false;
             }
             String type = file.getName().substring(lastDot + 1).toLowerCase();
-            Log.i("FileUtils","targetType:"+targetType+"-type:"+type);
+            if (TextUtils.isEmpty(type)) {
+                Log.i("FileUtils", "isEmpty filetype");
+                return false;
+            }
+            if (TextUtils.equals(targetType, "midi")) {
+                //兼容下mid格式
+                return TextUtils.equals(type, "midi") || TextUtils.equals(type, "mid");
+            }
+            Log.i("FileUtils", "targetType:" + targetType + "-type:" + type);
             return TextUtils.equals(targetType, type);
         } catch (Exception e) {
             e.printStackTrace();

+ 5 - 4
teacher/src/main/java/com/cooleshow/teacher/ui/web/HtmlActivity.java

@@ -1186,10 +1186,11 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             if (result != null) {
                 File file = UriUtils.uri2File(result);
                 if (file != null && file.exists()) {
-//                    if (!isMatchFile(file.getAbsolutePath())) {
-//                        ToastUtil.getInstance().showShort("请上传正确类型的文件");
-//                        return;
-//                    }
+                    if (!isMatchFile(file.getAbsolutePath())) {
+                        ToastUtil.getInstance().showShort("请上传正确类型的文件");
+                        upLoadFileFaile();
+                        return;
+                    }
                     UploadHelper uploadHelper = new UploadHelper(HtmlActivity.this, buckName);
                     uploadHelper.uploadFile(file);
                     uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {