ngCordova Download file


#1

I recently started working with ngCordova within an ionic application and currently I am stack with cordovaFile.downloadFile… I am currently performing my tests on an android device and I have managed to check if a directory exists “checkDir” with success. However, it wont work when I try to download a file on that directory.

The Code below shows the checkDir that works.

$scope.checkfile = function(){
    $cordovaFile.checkDir("/storage/sdcard0/videos/01/").then(function(result) {
        // Success! 
        $cordovaDialogs.alert('Wow!');
    }, function(err) {
        // An error occured. Show a message to the user
        $cordovaDialogs.alert('Error');
    });
};

The code below shows the downloadFile that doesn’t seem to be working.

$scope.download = function() {
    $ionicLoading.show({template: 'Loading...'});
    $cordovaFile.downloadFile("http://www.education.gov.yk.ca/pdf/pdf-test.pdf", "/storage/sdcard0/videos/01/", true, options).then(function(result) {
        // Success!
        $cordovaDialogs.alert('Wow!');
        $ionicLoading.hide();
    }, function(err) {
        // An error occured. Show a message to the user
        $cordovaDialogs.alert('Error');
        $ionicLoading.hide();
    });
};

Thanks in advance!


#2

The weird scenario here is that I don’t even get an error from the above code… Neither the Loading… modal leaves the screen and I don’t get a dialog either so I can get an indication of what is happening… Furthermore, I have added into AndroidManifest.xml the following permissions… :confused:

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

#3

I have managed to solve my issue the code below shows what I have changed…

$scope.download = function() {
$ionicLoading.show({template: 'Loading...'});
$cordovaFile.downloadFile("http://www.education.gov.yk.ca/pdf/pdf-test.pdf", "file:///storage/sdcard0/pdf/pdf-test.pdf", true,{}).then(function(result) {
    // Success!
    $cordovaDialogs.alert('Wow!');
    $ionicLoading.hide();
}, function(err) {
    // An error occured. Show a message to the user
    $cordovaDialogs.alert('Error');
    $ionicLoading.hide();
}); };

#4

Hi Michael,

Do you have working blank project with download capability and can you share it?