I am using phonegap file api to create a directory and create a file in the directory created. The directory is getting created, but the file is not getting created in the d
function download(URL, fileName){
var folderName = 'xyz';
var uri = encodeURI(URL);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function (fileSystem) {
var directoryEntry = fileSystem.root; // to get root path of directory
directoryEntry.getDirectory(folderName, {
create: true,
exclusive: false
}, onDirectorySuccess, onDirectoryFail);
var filename = fileSystem.root.toURL() + folderName + "/" + uri.substr(uri.lastIndexOf("/") + 1);
var fileTransfer = new FileTransfer();
fileTransfer.download(uri, filename,
function(entry) { // download success
var path = entry.toURL(); //**THIS IS WHAT I NEED**
window.plugins.toast.showLongBottom("Download Completed: " + entry.fullPath, function (a) {
}, function (b) {
});
},
function(error) {
console.log("error")
} // irrelevant download error
);`enter code here`
},
function(error) {
console.log("error2")
} // irrelevant request fileSystem error
);
function onDirectorySuccess(parent) {
// Directory created successfuly
console.log("Directory created successfuly: " + JSON.stringify(parent));
var fp = (parent.nativeURL) + fileName;
filetransfer(download_link, fp);
}
function onDirectoryFail(error) {
//Error while creating directory
alert("Unable to create new directory: " + error.code);
}
}