Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileTypeFromBase64 #610

Closed
phaux opened this issue Sep 9, 2023 · 4 comments
Closed

fileTypeFromBase64 #610

phaux opened this issue Sep 9, 2023 · 4 comments

Comments

@phaux
Copy link

phaux commented Sep 9, 2023

We need to know the mime type before we can parse it using fetch data url.

const type = fileTypeFromBase64(base64string) // add this

const blob = await fetch(`data:${type.mime};base64,${base64string}`)
    .then(resp => resp.blob())
@sindresorhus
Copy link
Owner

You can easily convert Base64 to a Buffer. I don't think this is common of enough need to support built-in.

Buffer.from(b64string, 'base64');

@sindresorhus sindresorhus closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2023
@phaux
Copy link
Author

phaux commented Sep 9, 2023

But Buffer.from is node only :/

@sindresorhus
Copy link
Owner

@phaux
Copy link
Author

phaux commented Sep 10, 2023

Yeah I know, but the fetch data url method is async and better on front-end where you want consistent 60fps. Just sayin.

What alternatives do we have according to that SO post:

  • atob which is for parsing base64 encoded strings, not any bytes.
  • Buffer.from - node only.
  • Use a library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants