TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob' Using angular

Hari Y 1 Reputation point
2022-10-06T09:14:25.407+00:00

HTML Page:

<input #csvReader type="file" name="myfile" class="btn btn-outlined btn-white mr-auto" id ="uploadUsers" accept=".csv" (change)="onChange($event)"/>

component.ts

onChange($event: any): void {

let files = $event.srcElement.files;

if (this.isValidCSVFile(files[0])) {

let input = $event.target;     

let reader: FileReader = new FileReader();    

reader.readAsText(input.files[0]);   

console.log("input.files[0] : ",input.files[0])    

reader.onload = () => {     

  let csvData = reader.result;     

  let csvRecordsArray = (<string>csvData).split(/\r\n|\n/);   

  console.log("csvRecordsArray : " + csvRecordsArray)   

  let headersRow = this.getHeaderArray(csvRecordsArray);   

 };     

reader.onerror = function () {     

  console.log('Error occured while reading file!');      

};     

}else{

this.snackBarService.showSnackBarErrorMessage("Please select CSV file.");     

this.reset();     

}

}

Note : Above code is worked on local machine, but not run on the server

Windows for business Windows Client for IT Pros Devices and deployment Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.