Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

Angular ng-src unable to load image from device

$
0
0

@rajamohammed wrote:

What im trying to achieve :

When the user clicks on a image placeholder the image is downloaded from the server to the device (to a specific location) , the downloaded image path is then stored in the $socpe and displayed to the user .

Below is my contorler

.controller('NDetailCtrl', function($scope, $state,$stateParams,$ionicLoading,$ionicHistory,$timeout,$cordovaFile,$cordovaFileTransfer) {

    $scope.image = '';

    // triggered on click
    $scope.downloadFile = function(image) {

    var url = "http://app.example.org/uploads/"+image ;
    var filename = url.split("/").pop();

    var targetPath = cordova.file.externalRootDirectory+filename;
    var trustHosts = true;
    var options = {};


$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
  .then(function(result) {

    // Success!

    console.log(JSON.stringify(result));

    $scope.resource =  result.nativeURL;
    // This return the file location as
    // file:///storage/emulated/0/[filename]
    $scope.image = true;

    console.log($scope.resource);

  }, function(error) {
    // Error
    alert('Error : Some Thing went wrong !');

  }, function (progress) {
    $timeout(function () {
      $scope.downloadProgress = (progress.loaded / progress.total) * 100;
    });
  });

};

})

I have whitelist config as well this one is inserted inside diviceready event

$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|file|blob|cdvfile|content):|data:image\//);

When i try to load the returned path using ng-src it doesn't display any thing , just a blank white space .

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>