FileReader not firing onloadend


#1

I’m trying to read a local file using the cordova-file-plugin. At the moment I’m able to read the content of local directories and select a single file. But I have problems to get the content of the file.

Here’s my function that’s called by clicking a button after selecting a file from list:

import() {
  window.resolveLocalFileSystemURL(this.file.nativeURL, this.gotFile, this.fail);
}

And here’re the two functions gotFile and fail:

fail(e) {
  console.log(e);
}


gotFile(fileEntry) {
  var file = fileEntry.nativeURL;

  fileEntry.file(function(file) {
    var reader = new FileReader();

    reader.onloadend = function(e) {
      console.log('onloadend()'); 
    };

    reader.readAsText(file);

    console.log(reader);
  }); 
}

I can see in the log the reader with all the wanted content of my file under result, but I’m not able to get it and use it. The readyState is 2, but all inside reader.onloadend isn’t called. With Ionic 1 this code works without any problems.

I would be very glad, if there’s anyone who can help me. Thanks in advance!


#2

Hi max, do you have news with that?


#3

Hi,
a few days after writing this, I’ve read about this issue somewhere else. I couldn’t find it again, but I remember that the problem was caused by an old version of zone.js which was used by the version of angular2 used by ionic 2 beta3. In newer versions of zone.js this issue was solved and it was annouced that in ionic 2 beta4 there will be one of this newer versions used. Therefore I stopped developing at this feature of my app and waited for beta 4. After update to ionic 2 beta4 I tried again and now it works for me without any problem and without any changes on my code.


#4

I would suggest a direct update to beta.6 because of a few issues in beta.4.


#5

Thanks for your advice, I’ve update to beta.6 a few days ago. But this issues was solved after updating to beta.4.