Skip to content

Instantly share code, notes, and snippets.

@rodrigodiasnoronha
Created August 24, 2022 19:42
Show Gist options
  • Select an option

  • Save rodrigodiasnoronha/a08095725442c8222e2dbd280b2a1030 to your computer and use it in GitHub Desktop.

Select an option

Save rodrigodiasnoronha/a08095725442c8222e2dbd280b2a1030 to your computer and use it in GitHub Desktop.
Abrir arquivo base64 em uma nova guia
const base64ImageData = `data:${doc.arquivo_base_64.ext == 'pdf' ? 'application' : 'image'}/${
doc.arquivo_base_64.ext
};base64,${doc.arquivo_base_64.arquivoBase64}`
const contentType = `${doc.arquivo_base_64.ext == 'pdf' ? 'application' : 'image'}/${
doc.arquivo_base_64.ext
}`
const byteCharacters = atob(base64ImageData.substr(`data:${contentType};base64,`.length))
const byteArrays = []
for (let offset = 0; offset < byteCharacters.length; offset += 1024) {
const slice = byteCharacters.slice(offset, offset + 1024)
const byteNumbers = new Array(slice.length)
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i)
}
const byteArray = new Uint8Array(byteNumbers)
byteArrays.push(byteArray)
}
const blob = new Blob(byteArrays, { type: contentType })
const blobUrl = URL.createObjectURL(blob)
window.open(blobUrl, '_blank')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment