@soumik wrote:
Hi guys,
I am new in ionic. I am trying to download a file form AWS, but unable to download it.
Could you please guide me on this topic.Below is my HTML code
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script src="lib/ngCordova/dist/ng-cordova.js"></script> <!-- compiled css output --> <link href="css/ionic.app.css" rel="stylesheet"> <script src="lib/ionic/js/ionic.bundle.js"></script> <script src="lib/ngCordova/dist/ng-cordova.min.js"></script> <script src="cordova.js"></script> <script src="js/app.js"></script>
Learn
<ion-content class="test"> <p class="heading"> embibe</p> </ion-content> <ion-footer-bar align-title="center" class="bar-positive"> <div class="buttons" data-ng-click="refresh()"> <button class="button">back</button> </div> <h1 class="title">Home</h1> <div class="buttons" data-ng-click="refresh()"> <button class="button">forward</button> </div> </ion-footer-bar>
Below is my app.js code
var App= angular.module('NativeApp', ['ionic','ngCordova', 'ngCordova.plugins.file']);
App.controller("NativeAppCtrl",NativeAppCtrl);
NativeAppCtrl.$inject=['$scope','$http', '$cordovaFile', '$rootScope', '$cordovaNetwork','$ionicPlatform'];function NativeAppCtrl($scope, $http, $cordovaFile, $rootScope, $cordovaNetwork, $ionicPlatform){
$ionicPlatform.ready(function($http) {alert(cordova.file.dataDirectory ); $scope.refresh=function(){ var isOnline = $cordovaNetwork.isOnline(); //alert(isOnline); if(isOnline){ var url = "https://embibe-cdn.s3.amazonaws.com/resources/images/ci/image02-436a1a74-f2ee-4537-b176-827aaa218ca8.png"; var targetPath = cordova.file.dataDirectory + "testImage.png"; var trustHosts = true var options = {}; alert(targetPath); $cordovaFileTransfer.download(url, targetPath, options, trustHosts) .then(function(result) { alert("success!"); }, function(err) { alert("error!"); }, function (progress) { $timeout(function () { $scope.downloadProgress = (progress.loaded / progress.total) * 100; }) }); } else{ alert("lost network!"); } }
});
}
Posts: 1
Participants: 1