im trying do download file but without success. Im using this code but on click it open image, but i dont want to do that .. i want to download that image. Any suggestion?
toDataURL(url) {
return fetch(url).then((response) => {
return response.blob();
}).then(blob => {
return URL.createObjectURL(blob);
});
}
then
async download() {
const a = document.createElement("a");
a.href = await toDataURL("https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-512.png");
a.download = "myImage.png";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
window.open(url , "_blank");
is simple solution for downloading a file with urla
element :a.setAttribute('download','')
. Or even simpler :a.download=''