Skip to content

Instantly share code, notes, and snippets.

@isc30
Last active June 12, 2023 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isc30/cd996814113869bef40a27d4af79f92d to your computer and use it in GitHub Desktop.
Save isc30/cd996814113869bef40a27d4af79f92d to your computer and use it in GitHub Desktop.
downloading binary data as a file
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