I try to decode base64 encoded string token in react native, atob not work and library like js-base64 not resolve the problem.
Someone have a solution ?
To decode a file with contents that are base64 encoded, you simply provide the path of the file with the --decode flag. As with encoding files, the output will be a very long string of the original file. You may want to output stdout directly to a file.
You can use react-native-pdf package (https://www.npmjs.com/package/react-native-pdf). If you want to show the pdf in your app , this package would be quite helpful as it supports loading PDFs from base64 string for both ios and android .
I find some simple way worked for me, the same api as node.
Install buffer
yarn add buffer
Usage:
console.log(Buffer.from("Hello World").toString('base64'));
console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'));
atob and btoa are not supported in JavascriptCore but works when the app runs under Chrome debugger, because JS code runs in Chrome when debugged. There are many base64 modules. https://github.com/mathiasbynens/base64 works fine for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With