2

I use this to download -

<a href={`${link}`} download="file">Download</a>

But it's not working for me. I use the Chrome browser. It just opens the file in the browser.

Shahid
  • 129
  • 10
  • What is the `Content-Disposition` header that is shown for the GET response in the dev tools? The [mdn docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download) show some information about the `download` attribute behavior and how it is influenced by the header info. – Martin Dec 13 '21 at 10:13

2 Answers2

1
function download(fileUrl, fileName) {
 let a = document.createElement("a");
 a.href = fileUrl;
 a.setAttribute("download", fileName);
 a.click();
}
Aliaga Aliyev
  • 415
  • 1
  • 6
  • 22
0

Try adding target="_blank":

<a href={`${link}`} download="file" target="_blank" >Download</a>
Sebastian
  • 414
  • 4
  • 6