Question

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
//request the persistent file system
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemFail);
}

function fileSystemSuccess(fileSystem) {
    var directoryEntry = fileSystem.root; // to get root path to directory
    directoryEntry.getDirectory("teste_recev", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail);
    var rootdir = fileSystem.root;
    var fp = rootdir.fullPath;
    fp = fp+"/teste_recev/image_name.jpg";
    var fileTransfer = new FileTransfer();
   fileTransfer.download("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/t1.0-1/c14.4.48.48/150734_264955536974736_682293823_t.jpg",fp,  
        function(entry) {
            alert("download complete: " + entry.fullPath);
        },
        function(error) {
            alert("download error source " + error.source);
            alert("download error target " + error.target);
            alert("upload error code" + error.code);
        }
    );
}
function onDirectorySuccess(parent) {
    console.log(parent);
}

function onDirectoryFail(error) {
    alert("Unable to create new directory: " + error.code);
}

function fileSystemFail(evt) {
    console.log(evt.target.error.code);

}

But have a error:
  1. dowload error source https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/t1.0-1/c14.4.48.48/150734_264955536974736_682293823_t.jpg
  2. download error target//teste_recev/image_name.jpg
  3. upload error code1

i have, the cordova.js in project, have link for cordova.js but have this erros if someone to help, really appreciate it.

Was it helpful?

Solution

Try like this

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function gotFS(fileSystem) {
           fileSystem.root.getDirectory("your dir", {create: true}, function fileSystemSuccess(fileSystem){
                fileSystem.getFile("dummy.txt",{create: true,exclusive:false},function gotFileEntry(fileEntry){
                    var path = fileEntry.fullPath.replace("dummy.txt","");
                    fileEntry.remove();
                    var fileTransfer = new FileTransfer();
                    fileTransfer.download(FILE_DOWNLOAD_URL, path+""+your -savedName,function(theFile){
                        alert("File Downloaded Successfully " + theFile.toURI());
                    },function(error){
                        alert("File Transfer failed" + error.message);
                    });
                },fail);
            });
    }, fail);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top