Last active
July 20, 2017 09:48
-
-
Save taufiksu/e286a438dc0725ad60a0f1d49cedd1f6 to your computer and use it in GitHub Desktop.
Cordova function for download file and store into public folder
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
function fileDownload(dirName, fileURL, fileName) { | |
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; | |
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsAccess, fsFail); | |
function fsAccess(fileSystem) { | |
fileSystem.root.getDirectory(dirName, { create: true, exclusive: false }, dirReady, dirFail); | |
} | |
function fsFail() { | |
console.log("Filesystem Access Failed"); | |
} | |
function dirFail() { | |
console.log("Directory Access Failed"); | |
} | |
function dirReady(entry) { | |
window.appRootDir = entry; | |
console.log(JSON.stringify(window.appRootDir)); | |
var fileTransfer = new FileTransfer(); | |
fileTransfer.download( | |
fileURL, | |
window.appRootDir.nativeURL + fileName, | |
function (theFile) { | |
console.log("download complete: " + theFile.toURL()); | |
}, | |
function (error) { | |
console.log(JSON.stringify(error)); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// add code to config.xml
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
// To Use It