Chrome App FileReader -
i'm trying make use of file system api in chrome app. i've tried sample code can find , can't simple text file read. i'm logging every step, , seems happen (or not happen) stops first time reference file reader object. creates fine, because can log .readystate, after can't seem set onload()event or execute .readastext().
here's i'm calling button:
function clickbutton(){ chrome.filesystem.chooseentry({type: 'openfile', acceptsmultiple: false}, function(fileentry){ if(chrome.runtime.lasterror) {console.warn("warning: " + chrome.runtime.lasterror.message);} else{ console.log(fileentry); var thing = new filereader(); console.log(thing.readystate); thing.onloadstart(function(){ console.log("started loading " & fileentry); }); console.log("added onloadstart"); console.log(thing.readystate); console.log(thing); thing.readastext(fileentry); console.log(thing.readystate); console.log(thing.result); } }); document.getelementbyid("status").innerhtml = "i did something"; }
i did read somewhere chrome doesn't allow access local files, chrome apps seem different. @ least, documentation seems suggest that.
the thing end in console fileentry object.
https://developer.chrome.com/apps/app_storage#filesystem
i've used example code right above link , still can't right. else have issue or know i'm doing wrong?
there difference between fileentry , file. need call fileentry's .file() method. so, replace
thing.readastext(fileentry);
with
fileentry.file(function(file) { thing.readastext(file) })
https://developer.mozilla.org/en-us/docs/web/api/fileentry#file
Comments
Post a Comment