JavaScript Base64 Examples
JavaScript provides two built-in functions (btoa and atob) to encode data to Base64 and decode it. Also, some objects have methods for encoding their values to Base64. In order to get to know them better, I suggest looking at the examples on this page.
Comments (12)
I hope you enjoy this discussion. In any case, I ask you to join it.
do you get the text from the file then encode that?????????
<!-- language: lang-js -->
console.log(btoa("password")); // cGFzc3dvcmQ=
<!-- end snippet -->
and for Angular 12+ something like this is what's been suggested around. using
Buffer.from().toString()
console.log(Buffer.from("Hello World").toString('base64')); // SGVsbG8gV29ybGQ=
console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('binary')) // Hello World