Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova android can't copy image from cache directory

Tags:

image

cordova

I have a working app that takes picture but I want to copy or move the picture from the cache folder to an other folder.I can't do it work, it returns me the error [object Object].

Regards

function copiePhoto() {
try {
    var fail = function (err) {
        alert(err);
    };
    window.resolveLocalFileSystemURI("file:///storage/emulated/0/Android/data/com.coolappz.capigo/cache/1427968060754.jpg", function (file) {
        window.resolveLocalFileSystemURI("file:///test", function (destination) {
            file.moveTo(destination, "test.jpg");
        }, fail);
    }, fail);
} catch (err) {
    alert("copie : " + err);
}

}

like image 200
Maher Tliba Avatar asked Mar 17 '23 13:03

Maher Tliba


1 Answers

After some hours of work I did it works :

function recupImage(imageURI) {
    window.resolveLocalFileSystemURI(imageURI, copiePhoto, fail);    
}

function copiePhoto(fileEntry) {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { 
        fileSys.root.getDirectory("photos2", {create: true, exclusive: false}, function(dir) { 
                fileEntry.copyTo(dir, fileEntry.name, onCopySuccess, fail); 
            }, fail); 
    }, fail); 
}

function onCopySuccess(entry) {
    alert('image copié dans le chemin : ' + entry.fullPath);
}

function fail(error) {
    alert(error.code);
}
like image 171
Maher Tliba Avatar answered Mar 19 '23 01:03

Maher Tliba