Skip to content

Instantly share code, notes, and snippets.

@rohmanhm
Last active August 4, 2022 09:05
Show Gist options
  • Save rohmanhm/ab05eb68cc344e37cf51f2384d392748 to your computer and use it in GitHub Desktop.
Save rohmanhm/ab05eb68cc344e37cf51f2384d392748 to your computer and use it in GitHub Desktop.
export function downloadFileFromBlob(fileName: string, blob: Blob) {
const url = window?.URL?.createObjectURL(blob);
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
setTimeout(() => {
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}, 200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment