Gallery does not show the image after download?

I have following code to save image from url to Download folder

    var filename = url.replace(/^.*[\\\/]/, ''); 
    var filePath = cordova.file.externalRootDirectory + 'Download/' + filename;
    $cordovaFile.downloadFile(url, filePath, true, {})
        .then(function(result) {
          // Success!
          $cordovaToast.showShortCenter('This picture has been saved!');
        }, function(err) {
          $ionicPopup.alert({ title: 'Error!', template: angular.toJson(err) });
        });

It saves the image successfully. I can explore the file in the SD card. But it is not visible in Galary app. When i search for it, i found that we should run some media scanner on that file.

How do i run media scanner? is there any api?

Hi veebha!

I dont know if you still have this problem, but the reason for images not to show up in the gallery is because the Android Media needs to be updated after doing downloads or creation of folders. I have the same issue but I think I found a solution here.

This is a plugin that allows Cordova to invoke Media Scanner just by using:
window.MediaScannerPlugin(successCallback, failureCallback)

I hope this works for you, I haven’t tried that yet but I will.

Let me know if it works for you!

Cheers!

1 Like