/* Blob包含两个参数(非必填): 包含实际数据的数组 数据的类型 */ let content = '123' let b = new Blob([content], {"type": "text/xml"}) let nb = b.slice(start, end) // 通过slice切割blob得到新的blob,分片上传用到此方法 // 通过blob下载文件 let a = documen.createElement('a') let href = window.URL.createObjectURL(b) // URL对象用于生成指向File对象或Blob对象的URL a.href = href a.download = '***.txt' a.click()
Blob对象的两个只读属性
1
Blob {size: 11, type: ''}
在Ajax操作中,如果xhr.responseType设为blob,接收的就是二进制数据
fileList对象
fileList对象就是input-file控件选取文件后的files属性的值
1
let file = document.getElementById('input').files[0] // files即fileList对象,可读取文件
拖拽方式上传文件,获取files
1 2 3 4 5 6 7 8 9 10 11 12
// 原生拖拽事件 drop var dropZone = document.getElementById('drop_zone'); dropZone.addEventListener('drop', handleFileSelect, false);