Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70894

Reading local file with cordova file plugin in Ionic 2

$
0
0

@max_maeuschen wrote:

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.

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>