用户需要在企业号上传word等文件,前端根据获取到的文件的type属性进行判断是否可以上传"application/msword"
,在手机上上传没有问题,但是在某一个用户的电脑上却出现了通过获取到的file对象中,type属性为"",
在网上查找各种资料后得到的结果:
浏览器中获取不到type属性不一定是代码的原因,而是系统中所安装的Microsoft Excel软件或注册表的原因,另外在MDN中的File对象中也找到这也一句描述:基于当前的实现,浏览器不会实际读取文件的字节流,来判断它的媒体类型。它基于文件扩展来假设;重命名为 .txt 的 PNG 图像文件为 “text/plain” 而不是 “image/png” 。
**开发者最好不要依靠这个属性,作为唯一的验证方案。**