Created
November 15, 2021 06:54
-
-
Save fysherman/ad82ca412b9e3bc42f8b8ef7b7526c7f to your computer and use it in GitHub Desktop.
Convert data to file and download in browser
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
//data: file data | |
// fileName: file's name to download | |
// typeFile: type file download. eg: text/html | |
function downloadFile(data, fileName, typeFile) { | |
const aEl = document.createElement('a') | |
const file = new Blob([data], { type: typeFile}) | |
aEl.href = URL.createObjectURL(file) | |
aEl.download = fileName | |
aEl.click() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment