📜  js 本地文件读取到 blob 变量 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:11.802000             🧑  作者: Mango

代码示例1
let file = new File(['hello', ' ', 'world'], 'hello_world.txt', {type: 'text/plain'});
//or let file = document.querySelector('input[type=file]').files[0];
let reader = new FileReader();
reader.onload = function(e) {
    let blob = new Blob([new Uint8Array(e.target.result)], {type: file.type });
    console.log(blob);
};
reader.readAsArrayBuffer(file);