Skip to content Skip to sidebar Skip to footer

Download File From Url?

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? toData

Solution 1:

Not an angular way, but using pure js : Fetch API

functiondownload(url, name) {
  fetch(url).then((response) => {
    return response.blob().then((b) => {
      const a = document.createElement("a");
      a.setAttribute("download", name);
      a.href = URL.createObjectURL(b);
      a.click();
    });
  });
}

download('https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-512.png', 'ninja.png')

Solution 2:

What about a simple <a> download link:

HTML

<a [href]="imageUrl"download>Download image</a>

component.ts

imageUrl:string = "https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-512.png"

Solution 3:

Try <a href="data:...." target="_blank"> OR use downloadify

Post a Comment for "Download File From Url?"