Javascript同时具有File和Blob用于文件表示,两者几乎都是一样的.有没有办法检查变量是否持有文件或Blob类型的数据?
解决方法
W3.org:
‘File对象是一个带有name属性的Blob对象,它是一个字符串;’
如果是文件:
var d = new Date(2013,12,5,16,23,45,600);
var generatedFile = new File(["Rough Draft ...."],"Draft1.txt",{type: 'text/plain',lastModified: d});
console.log(typeof generatedFile.name == 'string'); // true
如果是Blob:
var blob = new Blob(); console.log(typeof blob.name); // undefined
条件:
var isFile = typeof FileOrBlob.name == 'string';