![](/img/trans.png)
[英]failed to execute 'readAsText' on 'FileReader' :parameter 1 is not of type 'Blob'
[英]fileReader.readAsText() throwing 'FileReader': parameter 1 is not of type 'Blob'
我正在嘗試讀取CSV或Excel文件,以便將其轉換為表格。 現在,我只是創建了一個類以讀取輸入文件:
輸入為:
<input type="file" class="form-control-file" id="file_upload">
現在,我只是創建了一個類以讀取輸入文件:
class InputReader_tiqet{
constructor(input_id) {
this.inputId=input_id;
this.filetoLoad=document.getElementById("file_upload").files[0];
}
readFileData(){
this.filetoLoad = document.getElementById(this.inputId).files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent){
this.fileData = fileLoadedEvent.target.result;
};
fileReader.readAsText(this.fileToLoad, "UTF-8");
}
getData(){
return this.fileData;
}
}
我按如下方式運行它:
inputReader_object= new InputReader_tiqet("file_upload");
$("#file_upload").on('change', function(){
inputReader_object.readFileData();
//clean input field
this.val("");
});
當輸入文件更改時,出現以下錯誤:
Uncaught TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'.
解決的問題:this.filetoLoad而不是this.fileToLoad。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.