1,854 questions
TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob' Using angular
Hari Y
1
Reputation point
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
Sign in to answer