DEV Community

Sk
Sk

Posted on

Daily Dose of JavaScript: way to download files/blob objects, a bit dirty

createBlob = async function Blob(link){
        const file = await fetch(link)
        return file.blob()
  }  

downloadBlob =  async function download(link){
      const result = await this.createBlob(link);

      if(result){
         let atag = document.createElement("a");
            atag.download = 'myVid';
            atag.href = window.URL.createObjectURL(result);
            document.body.appendChild(atag);
            atag.click();
            document.body.removeChild(atag)
      }
  }



Enter fullscreen mode Exit fullscreen mode

if twitter is your thing come say hi Tweet to @MhlunguSfundo or drop a question i am happy to answer.

Top comments (0)