Last active
January 16, 2023 05:12
-
-
Save n4bb12/d44beb4a7080aae51136349cb7f7954f to your computer and use it in GitHub Desktop.
Download a in-memory content with a specific file type
This file contains 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
export function download({ | |
filename, | |
content, | |
contentType, | |
}: { | |
content: string | |
contentType: string | |
filename: string | |
}) { | |
const a = document.createElement("a") | |
const file = new Blob([content], { type: contentType }) | |
const url = URL.createObjectURL(file) | |
a.href = url | |
a.download = filename | |
a.click() | |
setTimeout(() => { | |
URL.revokeObjectURL(url) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment