Last active
June 12, 2023 04:26
-
-
Save isc30/cd996814113869bef40a27d4af79f92d to your computer and use it in GitHub Desktop.
downloading binary data as a file
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
function download_binary(binaryData, fileName, mime) | |
{ | |
file = new Blob([binaryData], { type: mime }); | |
downloadUrl = URL.createObjectURL(file); | |
// download the Blob | |
anchor = document.createElement('a'); | |
anchor.download = fileName; | |
anchor.href = downloadUrl; | |
anchor.dataset.downloadurl = mime + ":" + fileName + ":" + downloadUrl; | |
document.body.appendChild(anchor); | |
anchor.click(); | |
document.body.removeChild(anchor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment