Nakket
Nakket

Reputation: 620

How to download a file using Cordova File Transfer plugin in iOS

I have used the following code to download file:

$scope.onDownloadMusic = function( live ) {

    var downloadUrl = offlineUrl + fileName;
    var hostUrl = encodeURI(live.url);

    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        hostUrl,
        downloadUrl,
        function(entry) {
            alert('Your download has completed.');
        },
        function(error) {
            alert(error.source);
        },
        false,
        {
            headers: {
                "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            }
        }
    );
};

It works fine on Android. However, when I tried the same code on iOS, I always got an error.

I didn't know what went wrong. Any help is really appreciated.

Upvotes: 3

Views: 4703

Answers (1)

Nakket
Nakket

Reputation: 620

I finally found the solution:

Simple trick which takes me quite some time to investigate:

    var downloadUrl = encodeURI(cordova.file.dataDirectory + fileName);
    var hostUrl = encodeURI(live.url);

What's interesting here is encodeURI.

Upvotes: 5

Related Questions