In short, my issue revolves around reading a csv file from an android device using JavaScript's FileReader. Although my code was functioning properly a month ago, upon revisiting it recently I discovered that the onload
function no longer seems to be triggering.
When checking the console log, I observed that the object does indeed have the onload
function loaded, and both the file itself as well as its content are being read. Below, I will provide snippets of the relevant code:
readCSVFile(input: HTMLInputElement) {
var content = this.csvContent;
const files = input.files;
console.log("files: ", files);
if (files && files.length) {
const fileToRead = files[0];
console.log("step1");
var fileReader = new FileReader();
console.log("state 1: ", fileReader.readyState); //prints undefined, but should have been "0"
fileReader.onload = this.onFileLoad.bind(this);
console.log("fileReader: ", fileReader);
fileReader.readAsText(fileToRead, "UTF-8");
console.log("fileReader 2: ", fileReader.onload);
console.log("state 3: ", fileReader.readyState);
}
}
I'm inclined to believe that the 'onFileLoad' function is not the culprit, even though its first line contains a console.log("something")
statement which isn't appearing in the console output. Here are some noteworthy excerpts from the console log:
fileReader 2: Æ’ (fileLoadedEvent) {
console.log("step2");
var textFromFileLoaded = fileLoadedEvent.target.result;
this.csvContent = textFromFileLoaded;
console.log("Continut: ", t…
state 1: undefined