Last active
October 29, 2021 18:55
-
-
Save mauriciord/db2799c04c6588634d569da86daeb0e1 to your computer and use it in GitHub Desktop.
Creating the file based on the base64
This file contains hidden or 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 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