Skip to content

Instantly share code, notes, and snippets.

@mauriciord
Last active October 29, 2021 18:55
Show Gist options
  • Save mauriciord/db2799c04c6588634d569da86daeb0e1 to your computer and use it in GitHub Desktop.
Save mauriciord/db2799c04c6588634d569da86daeb0e1 to your computer and use it in GitHub Desktop.
Creating the file based on the base64
function base64ToArrayBuffer(base64Str: string) {
const byteCharacters = window.atob(base64Str);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
return byteArray;
}
function showDocument(base64Str: string, mimeType: string) {
const byteArray = base64ToArrayBuffer(base64Str);
const file = new Blob([byteArray], { type: mimeType + ';base64' });
const fileURL = URL.createObjectURL(file);
window.open(fileURL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment