Last active
February 4, 2022 23:07
-
-
Save max8hine/e07e5fe81a4ae6dc9d496e97f8e76a5b to your computer and use it in GitHub Desktop.
File Download with Javascript
This file contains hidden or 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
const downloadFile = (data: string, name: string) => { | |
const blob = new Blob([data], { type: 'octet-stream' }); | |
const href = URL.createObjectURL(blob); | |
const a = Object.assign(document.createElement("a"); { href, download: name, style: "display: none"}) | |
a.click(); | |
URL.revokeObjectURL(href); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment