Created
October 4, 2012 17:14
-
-
Save macdonst/3835045 to your computer and use it in GitHub Desktop.
FileTrasfer a bunch of files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var remoteFiles = []; | |
function downloadRemotePDF() { | |
var local2User = JSON.parse( localStorage["locallessons"] ); | |
$.each(local2User, function(key) { | |
remoteFiles.push(optionsJSON + local2User[key].idcountries + '/' + local2User[key].idcurriculum + '/' + local2User[key].idoptions + '/pdf/' + local2User[key].pdfname); | |
} | |
downloadFile(); | |
} | |
function downloadFile() { | |
// No files left, stop downloading | |
if (remoteFiles.length == 0) { | |
return; | |
} | |
var remoteFile = remoteFiles.pop(); | |
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1); | |
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) { | |
fileSystem.root.getFile(localFileName, {create: true, exclusive: false}, function(fileEntry) { | |
var localPath = fileEntry.fullPath; | |
if (device.platform === "Android" && localPath.indexOf("file://") === 0) { | |
localPath = localPath.substring(7); | |
} | |
var ft = new FileTransfer(); | |
ft.download(remoteFile, localPath, function(entry) { | |
// Do what you want with successful file downloaded and then | |
// call the method again to get the next file | |
downloadFile(); | |
}, fail); | |
}, fail); | |
}, fail); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gidday,
Thanks man ... same as above. :p