Skip to content

Instantly share code, notes, and snippets.

@jfoshee
Created June 7, 2022 23:44
Show Gist options
  • Save jfoshee/07f5575989651005243f5541518b470a to your computer and use it in GitHub Desktop.
Save jfoshee/07f5575989651005243f5541518b470a to your computer and use it in GitHub Desktop.
function downloadBlob(blob: Blob, filename: string): void {
const downloadLink = document.createElement('a');
document.body.appendChild(downloadLink);
downloadLink.style.setProperty('display', 'none');
const objectUrl = URL.createObjectURL(blob);
downloadLink.href = objectUrl;
downloadLink.download = filename;
downloadLink.click();
URL.revokeObjectURL(objectUrl);
downloadLink.remove();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment