Skip to content

Instantly share code, notes, and snippets.

@tosin2013
Created December 6, 2016 04:41
Show Gist options
  • Select an option

  • Save tosin2013/eb148c73ff0e3d45f6958302911a0514 to your computer and use it in GitHub Desktop.

Select an option

Save tosin2013/eb148c73ff0e3d45f6958302911a0514 to your computer and use it in GitHub Desktop.
ionic framework download image to device
$scope.Download = function () {
ionic.Platform.ready(function(){
var url = "http://3.bp.blogspot.com/-XchURXRz-5c/U5ApPOrPM9I/AAAAAAAADoo/YZEj4qeSlqo/s1600/Final-Fantasy-XV-Noctis-Red-Eyes.png";
var filename = url.split("/").pop();
var targetPath = cordova.file.externalRootDirectory + filename;
$cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) {
console.log( 'Save file on '+targetPath+' success!');
}, function (error) {
console.log('Error Download file');
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}, function (progress) {
$scope.downloadProgress = (progress.loaded / progress.total) * 100;
console.log($scope.downloadProgress );
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment