Reputation: 7709
I want to initiate a file download from react, such that the browser downloads it as any regular file.
When I use fetch, I can download the file and do what I want, but is not downloaded with the browsers download manager. The files are rather large, that is why I want the browser to manage the download.
Upvotes: 1
Views: 3822
Reputation: 1005
I asked you if you have the full URL to the file. If you want to start the download from a link, use the solution Kielstra provided. If you want to start the download using javascript, use the following code:
window.location = url_to_file;
Upvotes: 2
Reputation: 535
If you have the URL to the file that you want to be downloaded, you can simply create a link to it with the download
attribute.
<a href="link_to_file" download>Download</a>
Upvotes: 2