I\'ve been trying to copy file named versions.txt from applicationDirectory to externalApplicationStorageDirectory using cordova but code fails.
here is the code
I finally got a functioning broader no specific/case function to copy a file having a baseFileURI
to a temporary (fileSystem == LocalFileSystem.TEMPORARY
) or persistent (fileSystem == LocalFileSystem.PERSISTENT
) APP directory, the destiny file having the name destPathName
.
It uses the cordova-plugin-file plugin.
function copyFile(baseFileURI, destPathName, fileSystem){
window.resolveLocalFileSystemURL(baseFileURI,
function(file){
window.requestFileSystem(fileSystem, 0,
function (fileSystem) {
var documentsPath = fileSystem.root;
console.log(documentsPath);
file.copyTo(documentsPath, destPathName,
function(res){
console.log('copying was successful to: ' + res.nativeURL)
},
function(){
console.log('unsuccessful copying')
});
});
},
function(){
console.log('failure! file was not found')
});
}
Use this function, for example, like this
copyFile("file:///storage/emulated/0/Android/data/com.form.parking.violation/cache/IMG-20180505-WA0004.jpg",
"myImg.jpg",
LocalFileSystem.TEMPORARY);