How to set downloaded image from AWS as an image via ng-src


#1

Hello everyone!
So I’ve been writing an app, which downloads images from AWS and sets it in the view, as

The code I am using is below:
function DownloadImages($localstorage, $cordovaFile, $ionicPlatform, $ionicLoading) {
var vm = this;
var test = {};

    vm.createDirectoryForImages = function (directory) {
        $ionicPlatform.ready(function () {
        }).then(function () {
            $cordovaFile.createDir(cordova.file.dataDirectory, directory, true)
                .then(function (entry) {

                }, function (error) {
                    alert("Could not create directory: " + error.status);
                })
        });
    };

    vm.download = function (directory, filename) {
        $ionicLoading.show({
            template: '<ion-spinner icon="spiral"></ion-spinner> </br>Downloading...'
        });
        var hike = JSON.parse($localstorage.get("hikelistandinformation"));
        var url = hike.photosUrl + "1.png";
        vm.createDirectoryForImages(directory);
        $ionicPlatform.ready(function() {
        }).then(function() {
            var ft = new FileTransfer();
            ft.download(url, cordova.file.dataDirectory + directory + "/" + filename, function successfullyDownloaded(entry) {
                return entry.toURL();
                $ionicLoading.hide();
            }, function error(error) {
                $ionicLoading.hide();
                alert("Download error: " + error);
            }, true, {});
        });


        //fileTransfer.download(url, cordova.file.dataDirectory + "LanikaiPillbox")
    };
}

However, whenever I try to set the image source as the entry url, nothing appears on the view. I have tried toInternalURL(), and fullPath(), but nothing seems to work.

Any advice would be greatly appreciated! Thanks in advance!


#2

Turns out my code was perfectly fine. It was a problem with the emulator.
I am using Genymotion, and I ran my app using the command, “ionic run android -l c -s” and apparently emulators don’t have the ability to get from native directories.
I ran it on my actual device, and the image shows. For anyone else that runs into the same problem that I just encountered, try to install and run your app on your phone!