Skip to content

Instantly share code, notes, and snippets.

@ravindranathakila
Forked from dhavaln/filesystem.js
Created April 4, 2014 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravindranathakila/9969239 to your computer and use it in GitHub Desktop.
Save ravindranathakila/9969239 to your computer and use it in GitHub Desktop.
/**
* Prepare the App Folder
*/
(function(){
window.appRootDirName = ".myapp";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("device is ready");
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function fail() {
console.log("failed to get filesystem");
}
function gotFS(fileSystem) {
console.log("filesystem got");
fileSystem.root.getDirectory(window.appRootDirName, {
create : true,
exclusive : false
}, dirReady, fail);
}
function dirReady(entry) {
window.appRootDir = entry;
console.log(JSON.stringify(window.appRootDir));
}
})();
function downloadImage(url, success, err){
console.log('download image ' + url);
var fileName = new Date().getTime() + ".png";
ft = new FileTransfer();
ft.download(
url,
window.appRootDir.fullPath + "/" + fileName,
function(entry) {
console.log("download complete: " + entry.fullPath);
success(entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
err(error);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment