How to upload (save) url image to our photo album using angularjs?

I am new to angularjs and my project runs on android and IOS platforms using angular and ionic. I need to save an image in my phone’s photo album ( IOS and Andorid support ) with the image url. I know that cordova plugins can download images from url, but I cannot figure out how to install cordova-plugin-file-transfer. Is there any other easier way to achieve this feature? Thank.

angular.module('myApp', []);

angular.module('myApp').controller('HomeCtrl', ['$scope', '$http', function($scope, $http) {

  $scope.saveImg = function(imgUrl){
   var hideSheet = $ionicActionSheet.show({
                        buttons: [
                            {text: 'save image'},
                            {text: 'copy link'},
                        ],
                        cancelText: 'cancel',
                        cancel: function () {
                        },
                        buttonClicked: function (index) {
                            if (index == 0) {//save image here
                               
                            }
                        }
                    });

  }
 
}]);
<img ng-src="{{imgUrl}}" on-hold="saveImg(imgUrl)">
Run codeHide result
+4
source share
1 answer

First you need to install the plugin using the CLI:

cordova plugin add cordova-plugin-file-transfer

ngCordova

$cordovaFileTransfer :

var app= angular.module('myApp', ['ngCordova']);

    app.controller('HomeCtrl', ['$scope', '$http', '$cordovaFileTransfer',function($scope, $http,$cordovaFileTransfer) {

    var url = "http://cdn.wall-pix.net/albums/art-space/00030109.jpg"; // your url
        var targetPath = cordova.file.documentsDirectory + "testImage.png"; // filename
        var trustHosts = true;
        var options = {};
    $scope.trans=function(){
        $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
          .then(function(result) {
            // Success!
          }, function(err) {
            // Error
          }, function (progress) {

          });

       }

    }]);

: http://ngcordova.com/docs/plugins/fileTransfer/

+1

Source: https://habr.com/ru/post/1677888/


All Articles