In my angular 4 application I have a gallery with some thumbnails, every thumbnails have a download button.
I want to start the download of the image when this butto
Finally I use this method:
this.mediaService.getImage(downloadLink).subscribe(
(res) => {
const a = document.createElement('a');
a.href = URL.createObjectURL(res);
a.download = title;
document.body.appendChild(a);
a.click();
});
}
To direcly download the image you can try with :
downloadImage(downloadLink) {
this.mediaService.getImage(downloadLink).subscribe(
(res) => {
const fileURL = URL.createObjectURL(res);
window.location.href = fileUrl;
}
);
}