0

I have stored the file in my Firebase storage and I got the download URL as well. How do I initiate download in the browser? Right now it is only opening a new window with the file. Here is what I tried:

downloadFile=(file)=>{
        var element=document.createElement('a');
        element.style.display= "none";
        element.setAttribute('href', file.fileUrl)
        element.setAttribute('download', file.filename)
        document.body.appendChild(element)
        element.click()
        document.body.removeChild(element)
    } 
Amulya Dubey
  • 157
  • 1
  • 10
  • What type of file? Default browser behavior is to open files in browser which it can open instead of downloading it (for example .pdf). – Jax-p Jul 02 '20 at 15:37
  • .pdf as well as .jpeg files – Amulya Dubey Jul 02 '20 at 15:39
  • Does this answer your question? [(HTML) Download a PDF file instead of opening them in browser when clicked](https://stackoverflow.com/questions/6794255/html-download-a-pdf-file-instead-of-opening-them-in-browser-when-clicked) – Jax-p Jul 02 '20 at 15:42

0 Answers0