Download image from url in Angular 5
14,048
This is not an angular issue. You can only use download
attribute to force download of an image/file, if:
- the server also says it should be downloaded, or
- the image comes from the same domain.
It's an issue of cross-origin hrefs.
https://stackoverflow.com/a/17527821/4899523
https://stackoverflow.com/a/49736875/4899523
Author by
Jorge Monroy
Updated on June 04, 2022Comments
-
Jorge Monroy almost 2 years
I have an URL in which the image that I need to download is. I want to make a button to download it. I tried this two options:
const a = document.createElement('a'); a.href = ImageURL; a.download = title; document.body.appendChild(a); a.click();
and
window.location.href = t;
But both options just open a new window with the image.
Is there a way to instead of getting a new window the file just get downloaded?
-
Abdul Rafay over 5 yearsdoes the image comes from the same domain?
-
Jorge Monroy over 5 yearsNo, it comes from a url of CARTO, the Static Image API.
-