jquery中输入类型文件的前缀"application/"是什么?



根据我的理解, 当我从安装了 MS Excel 的 PC 上传.xlsx文件时,它给了我 type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,当我从未安装 MS Excel 的 PC 上传相同的文件时,它给了我 type="。以下 jquery 代码在 if 条件中签入两次,作为inputFile.type="application/">

$("#btnUpload").change(function () {
var inputFile = $(this).get(0).files[0];
if (inputFile != undefined || inputFile != null) {
if (inputFile.type == ".csv" || inputFile.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || inputFile.type == "application/vnd.ms-excel") {
$("#uploadedFileName").html(inputFile.name)
} else {
errorToast("Please select valid file format");
}
} else {
errorToast("Please select file");
}
});

请帮助我解决应用程序/前缀的角色。 或纠正我的理解。

你说的是不同的MIME类型。以下是 MIME 类型的完整列表: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

如您所见,"应用程序/"有不同的选项。如果PC没有安装任何excel,则不应影响您正在谈论的文件类型。

这是另一个应该可以帮助您的问题: JS和type.match作为文件MIME类型 - 需要建议

最新更新