const beforeUpload = file => { var reader = new FileReader(); reader.readAsDataURL(file); //轉化二進制流,異步方法 reader.onload = function(){ //完成后this.result為二進制流 console.log(this.result,"0-00-"); var base64Str = this.result; var startNum = base64Str.indexOf("base64,"); startNum = startNum*1 + 7; //去除前部格式信息(如果有需求) var baseStr = base64Str.slice(startNum); console.log(baseStr,"二進制數據!!!") } }