Created
May 19, 2020 15:05
-
-
Save Neugierdsnase/9bca6e01564f0df78fc08a95a279fc72 to your computer and use it in GitHub Desktop.
directly download a file from a server in the 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
export const downloadFile = (data: string, type: string, fileName: string) => { | |
const url = window.URL.createObjectURL(new Blob([data])) | |
const a = document.createElement('a') | |
a.href = url | |
switch (type) { | |
case 'text/csv': | |
default: | |
a.download = `${fileName}.csv` | |
} | |
a.click() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment