Chrome App Access External Resources With Javascript / Jquery / Angularjs
I am building a Chrome app that visualizes some data. My data is collected separately and is stored in a local folder that is unrelated to the Chrome app. I am using Angular + D3,
Solution 1:
To gain access to an arbitrary directory, you need to use the fileSystem.chooseEntry function, which will prompt the user to select a directory, and then return a handle to you. Here is an example:
You must first add the necessary permissions to your manifest file:
"permissions":[{"fileSystem":["directory","retainEntries"]}]
To read a file:
chrome.fileSystem.chooseEntry({ type: 'openDirectory' }, function (dirEntry) {
dirEntry.getFile('file.json', {}, function (fileEntry) {
fileEntry.file(function (file) {
var reader = newFileReader();
reader.onloadend = function (e) {
var result = JSON.parse(this.result);
console.log(result);
};
reader.readAsText(file);
});
});
});
To retain your access to a directory across sessions, you can use retainEntry to get an id which you can save, and later use with restoreEntry to regain access to the directory. This way the user only has to select the directory once.
Post a Comment for "Chrome App Access External Resources With Javascript / Jquery / Angularjs"