0

I have a file that I want to download on click. When I click on the link the download is launched an at the end I am told that the file is not found. Below is the content of my tag.

<a href="/media/{{file.filePath}}" download>Download</a>

But if I add the base url like this :

<a href="https://www.example.com/media/{{file.filePath}}" download>Download</a>

On click the file is opened in the browser while I want to download it.

Thanks in advance

  • 2
    [_"`download` only works for same-origin URLs"_](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a). Given that you need to add the base URL for the link to work you're likely running into that limitation (in other words, your web app is not being hosted on the same origin URL as your files). – robertklep Jan 13 '23 at 14:39
  • I think this is what you are looking for: https://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript – Unknown Jan 13 '23 at 14:39

1 Answers1

0

you can use this snippet of code I wrote

<a href="{{ 'https://www.example.com/media/' + file }}" download>Download</a>