3

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.

Nakket
  • 620
  • 7
  • 18

1 Answers1

5

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.

Nakket
  • 620
  • 7
  • 18
  • 1
    This works! Great!... other references: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html#installation – joemalski Jan 18 '17 at 04:57