Reputation: 47
I am using this code to get the image download. please suggest me what code I need to add to download the image from API response in angular js.
var lang = locale.getLocale();
var token = AuthToken.get();
Restangular.one("wallpaper").customGET
(undefined, {
'X-Authorization':'Bearer ' + token,
'Accept-Language':lang,
'accept-encoding': 'gzip, deflate, sdch',
'accept':'image/jpeg'
})
.then(function(res){
scope.image=res;
modalInstance = $modal.open(opts);
$rootScope.reqLoading = false;
});
Upvotes: 3
Views: 1110
Reputation: 650
you can utilize the below code-
// download via the download attribute
var a = document.createElement('a');
a.download = 'test.png';
a.href = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQcWzAJb0c3t1waqim9j4-vBqXWHXcgjzV8FRARcxTOp8wxtvBc';
a.click();
var a = document.createElement('a');
a.download = 'test.png';
a.href = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQcWzAJb0c3t1waqim9j4-vBqXWHXcgjzV8FRARcxTOp8wxtvBc';
a.click();
Upvotes: 1