Error writing Cordova FileTransfer file (code 1)

I am using Cordova 4.2.0 for Android.

I have some problems to get the FileTransfer plugin . I believe there is a write error

exception:".myApp\/contentImages\/20150110220101.jpg: open failed: ENOENT (No such file or directory)"

filename was previously tested and does not yet exist:

rootFS.getFile('.myApp/contentImages/'+file,{create:false},
    function(){
        console.log(file+' already exists');
    },
    function(error){
        console.log(file+" does not exist locally");
        console.log("Error #"+error.code);
        download(file);
    }
);

And here is the download function:

function download (filename){
    var localPath = rootFS.fullPath+'/.myApp/contentImages/'+filename;
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        encodeURI('http://distantApp/contentImages/'+filename), // This file exists
        localPath,
        function(entry) {
            console.log("download complete: " + entry.fullPath);
        },
        function (error) {
            console.log('download error: ' + error.code + ": "+error.exception+" ; source " + error.source+" ; target " + error.target);
        }
    );
}

What could be the problem?

CHANGE Code forrootFS

function onDeviceReady(){
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function(){
        console.log("error requesting LocalFileSystem");
    });
}
function gotFS(fileSystem) {
    console.log("got filesystem: "+fileSystem.name); // displays "persistent"
    console.log(fileSystem.root.fullPath); // displays "/"
    window.rootFS = fileSystem.root;
}
+4
source share
2 answers

The problem was caused by updating Cordoba from a previous version.

The local file path was not correctly identified: it is .fullPathnow outdated and should be replaced with .toURL().

+11
source

, FileTransfer, , , .

: http://www.html5rocks.com/en/tutorials/file/filesystem/, , , , :

fs.root.getFile() . , . , , .

, , . .myapp contentImages.

+2

All Articles