0

Upon selecting an XML file with an open file dialog I want to read the contents of this file into some variable as a string.

I found here the following code. How can I return "theBytes" from processFile ?

Thank you in advance, Zvika

    public processFile(theFile)

{

return function(e) 
{ 
    var theBytes = e.target.result; 
    console.log (theBytes); 
}

}

var f = event.files[0];
let fileReader = new FileReader();
fileReader.onload = this.processFile(f);
fileReader.readAsText(f);
Zvi Vered
  • 459
  • 2
  • 8
  • 16

1 Answers1

0

the onload callback needs to be assigned to a callback function you are executing the function and assigning the response of processFile.

You need to assign the callback like this

fileReader.onload = this.processFile
joyBlanks
  • 6,419
  • 1
  • 22
  • 47