Attic V
Attic V

Reputation: 38

atob() and btoa() use cases

What are the use cases for atob() and btoa() other than when trying to prevent communication problems in information transfer?

I've researched this online, but I didn't find anything other than information transfer communication problems. This is the resource that I found: atob() and btoa()

Upvotes: 0

Views: 191

Answers (1)

edemaine
edemaine

Reputation: 3130

See what is base 64 encoding used for.

In particular, on the web, base-64 encoding is useful for contexts where binary data is forbidden, which includes much of HTML. For example, if you want to inline a PNG image file into a URL, for use in an <img src> for example, you can write data:image/png;base64,... where ... is the base-64 encoding of the PNG file. btoa is useful for generating such URLs, like so:

const url = "data:image/png;base64," + btoa(pngContent);

Upvotes: 1

Related Questions