我正在处理一个小文件上传脚本(学习经验),我注意到在选择微软办公室相关文件(.doc或者.docx例如)时,文件对象没有指定类型:
对于.doc文件,我原本期望的类型是"application/msword"和.docx一样的思路"application/vnd.openxmlformats-officedocument.wordprocessingml.document".
在无法确定类型的情况下,查看文件扩展名并将其与"预期"内容/ mime类型匹配的正确操作过程是什么?
示例脚本:
var fileSelect = document.getElementById("fileSelect"),
fileElem = document.getElementById("fileElem");
fileSelect.addEventListener("click", function (e) {
if (fileElem) {
fileElem.click();
}
e.preventDefault();
}, false);
function handleFiles(files) {
console.log(files);
}