Created
September 12, 2022 21:01
-
-
Save michael-lynch/aa6299bba89d6d01c1c67cfe627abcbc to your computer and use it in GitHub Desktop.
Download Blob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/68146412/2262604 | |
export const downloadBlob = ({ content, filename, contentType }) => { | |
// create blob | |
const blob = new Blob([content], { | |
type: contentType || 'text/csv;charset=utf-8;', | |
}); | |
const url = URL.createObjectURL(blob); | |
// create link to download it | |
const anchor = document.createElement('a'); | |
anchor.href = url; | |
anchor.setAttribute('download', filename); | |
anchor.click(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment