0
votes

I have a cordova app with functionality to download a pdf doc and store in a cordova file location. Any help or advice would be appreciated.

cordova version : 6.4.0

plugin version : cordova-plugin-file-transfer 1.4.0 "File Transfer"

platform : ios 10.2.1

url returning error code 2 :

file:///var/mobile/Containers/Data/Application/4FC21BCF-DFC4-4A85-BA17-1F9C300B45F3/Documents/4092477_Unlock Scanner Guide.pdf

Here is the function :

function downloadAsset(err) {
isDownloaded = true;
window.resolveLocalFileSystemURL(cordova.file.documentsDirectory, function (dirEntry) {
    console.log('file system open: ', dirEntry);
    target = dirEntry.toURL();
    target = target + fileName;
    var fileTransfer = new FileTransfer();
    console.log("About to start transfer");
    console.log(target+fileName);
    fileTransfer.download(assetURL, target,
        function(entry) {
            console.log("Success!");
            appStart(target);
        }, 
        function(e) {
            console.log("Error");
            console.dir(e);
        });
}, resOnError);

}

1

1 Answers

1
votes
var url = "YOUR URL";
var dest = "YOUR DEST FILE PATH";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
    fs.root.getFile(dest, { create: true, exclusive: false }, function (fileEntry) {
        var fileTransfer = new FileTransfer();
        fileTransfer.download(
            encodeURI(url),
            fileEntry.toURL(),
            function(entry){
                //DOWNLOAD OK
            },
            function(err){
                //ERROR
            },
            null,
            {}
        );
    }, function(err){
        //ERROR
    });
}, function(err){
    //ERROR
});