Created
September 27, 2016 03:01
-
-
Save syads321/9651b9c23f2126417da6ae5e11fd3e3a to your computer and use it in GitHub Desktop.
Cordova Download Multiple Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('starter', ['ionic','ngCordova']) | |
.config(['$compileProvider', function($compileProvider) { | |
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|content|file|assets-library):/); | |
}]) | |
.controller('Main', ["$ionicPlatform", "$cordovaFileTransfer", "$q", "$scope", | |
function($ionicPlatform, $cordovaFileTransfer, $q, $scope) { | |
console.log("running Main controller"); | |
$scope.images = []; | |
$ionicPlatform.ready(function() { | |
//resources to download | |
var resources = [ | |
"https://placekitten.com/g/200/300", | |
"https://placekitten.com/g/200/350", | |
"https://placekitten.com/g/400/350", | |
"https://placekitten.com/g/300/200", | |
"https://placekitten.com/g/188/188" | |
]; | |
var promises = []; | |
resources.forEach(function(i,x) { | |
var targetPath = cordova.file.documentsDirectory + "image"+x+".jpg"; | |
promises.push($cordovaFileTransfer.download(i, targetPath, {}, true)); | |
}); | |
$q.all(promises).then(function(res) { | |
console.log("in theory, all done"); | |
for(var i=0; i<res.length; i++) { | |
$scope.images.push(res[i].nativeURL); | |
} | |
}); | |
}); | |
}]) | |
.run(function($ionicPlatform) { | |
$ionicPlatform.ready(function() { | |
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard | |
// for form inputs) | |
if(window.cordova && window.cordova.plugins.Keyboard) { | |
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); | |
} | |
if(window.StatusBar) { | |
StatusBar.styleDefault(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment