Skip to content

Instantly share code, notes, and snippets.

@Sov3rain
Created December 6, 2022 13:14
Show Gist options
  • Save Sov3rain/a57ec45e384601fa894e811ff5a71c65 to your computer and use it in GitHub Desktop.
Save Sov3rain/a57ec45e384601fa894e811ff5a71c65 to your computer and use it in GitHub Desktop.
save a blob as a file
const blobUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = blobUrl;
link.download = fileName;
document.body.appendChild(link);
// link.click() does not work on the latest Firefox and some modern browsers.
link.dispatchEvent(
new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window,
}),
);
document.body.removeChild(link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment