Published on

Blobs

Authors
  • avatar
    Name
    Timothy Blanks

use fetch to convert a encoded url to a blob, or use this when source is unknown to create a good blob

convert a url or blob to new blob and open in new tab

fetch(oldblob)
  .then((response) => response.blob())
  .then((newBlog) => {
    window.open(URL.createObjectURL(newBlog), '_blank')
  })

Mock anchor click to download in memory blob

// this will mock clicking an anchor tag, can mock file download with name suggeston
const link = document.createElement('a')
link.download = 'testsfd.pdf'
link.href = URL.createObjectURL(newBlog)
link.click()