javascript - 为什么我所有的文件上传都跳过了 else if 条件?
问题描述
我有一个检查文件类型的功能。这一次,我想检查正确的文件和足够的文件大小。如果文件扩展名正确但文件大小大于 10MB,那么它应该抛出alert();
内部else if()
条件块。相反,它被跳过了。
我正在使用 37.3MB 的 .mov 文件对其进行测试
我究竟做错了什么?
function fileValidationWinnerPhoto() {
const realFileBtn = document.getElementById("real-file");
let filePath = realFileBtn.value;
let maxSize = 10485760;
// Allowing file type
let allowedExtensions = /(\.jpg|\.jpeg|\.png|\.bmp|\.mov|\.MOV)$/i;
if (!allowedExtensions.exec(filePath)) {
alert('Invalid file type');
realFileBtn.value = '';
return false;
} else if(allowedExtensions.exec(filePath) && realFileBtn.files[0].size > maxSize) {
alert("You have the correct file type but your uploaded file is too large! Try uploading a file that's less than 10MB!");
return false;
} else {
console.log("file accepted");
fileAcceptedFlag = true;
}
return filePath;
}
解决方案
推荐阅读
- python-3.x - 将热图应用于极坐标图?
- java - Android 构建错误 com.google.firebase:firebase-core:16.0.8
- python - 安装anaconda3和python2.7后需要安装Python3
- google-apps-script - 如果 C 列为“否”,则更新 A 列的当前时间
- python - 在 Python 中将 JSON 数据输出转换为 HTML-TABLE 格式 - Flask?
- javascript - 将 Electron 与 Parcel 和 Babel 7 一起使用时出现“意外标识符”
- javascript - 有没有办法在同一个反应元素内的钩子调用之间进行交互
- unity3d - Unity Editor:检查是否因为场景正在关闭而调用 OnDestroy() 方法
- memory-management - 垃圾收集是否需要更大的内存占用?
- r - 在R中的`$`登录后使用替代品