Maher Tliba
Maher Tliba

Reputation: 491

Cordova android can't copy image from cache directory

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);
}

}

Upvotes: 4

Views: 1305

Answers (1)

Maher Tliba
Maher Tliba

Reputation: 491

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);
}

Upvotes: 7

Related Questions