Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

W3C/PhoneGap FileReader - how to use?

I am working with PhoneGap (which implements a W3C FileReader for its file access), and there are a ton of tutorials online, but they all seem to lead to a dead end. Basically, they show you how to set everything up, but in the end, they all get to a place where it says:

myReader.readAsText(file);

What I am confused about is...what exactly does that do? Does it return some sort of index array? Can I use something along the lines of while(!feof)? How can I actually access what it has just read?

like image 372
antonpug Avatar asked Dec 02 '25 14:12

antonpug


1 Answers

Here is a bit more of an example:

var reader = new FileReader();
reader.onloadend = function(evt) {
    console.log("Read as data URL");
    console.log(evt.target.result);
};
reader.readAsText(file);

So if you pass in a FileEntry object to readAsText once the file is completely read the onloadend function, that you provide, will be called. The property evt.target.result will contain the full text of the file you wished to read.

like image 130
Simon MacDonald Avatar answered Dec 04 '25 04:12

Simon MacDonald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!