1

I have a url, ex: https://firebasestorage.googleapis.com/v0/b/chat-room-36b5c.appspot.com/o/images%2FWhatsApp%20Video%202022-11-03%20at%2021.15.22.mp4?alt=media&token=444957b3-a044-46d1-bab0-c3dccd0faf7f I would like to try and download it so it saves to my computer with js.

const download = (url) => {
  console.log(url);
  //is the url from above
};

I tried creating an anchor (a) tag and doing a .click() but because of CORS, I am not aloud. I know thats why cors was made, however I am using a service called firebase storage which is meant to store files?

I tried this:

function download(url) {
    fetch(url).then(res => res.blob()).then(file => {
      let tempUrl = URL.createObjectURL(file);
      let aTag = document.createElement("a");
      aTag.href = tempUrl;
      aTag.download = "filename";
      document.body.appendChild(aTag);
      aTag.click();
      aTag.remove();
    })
  }

Access to fetch at (URL) from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  • Then How Can I download It @Phil? – LolPerson292 Nov 04 '22 at 08:44
  • Sorry, I'm wrong. If the URL is on a different domain, [you cannot force it to download](https://stackoverflow.com/a/59031245/283366) – Phil Nov 04 '22 at 08:46
  • Have you updated [CORS for Firebase Storage](https://stackoverflow.com/questions/37760695/firebase-storage-and-access-control-allow-origin)? – Dharmaraj Nov 04 '22 at 12:33

0 Answers0