Skip to content

Instantly share code, notes, and snippets.

@michael-lynch
Created September 12, 2022 21:01
Show Gist options
  • Save michael-lynch/aa6299bba89d6d01c1c67cfe627abcbc to your computer and use it in GitHub Desktop.
Save michael-lynch/aa6299bba89d6d01c1c67cfe627abcbc to your computer and use it in GitHub Desktop.
Download Blob
// 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