12

React Native has a binaryToBase64 util that accepts ArrayBuffer for base64 conversions:

var utf8 = require(‘utf8’);
var binaryToBase64 = require(‘binaryToBase64’);

var text = ‘foo © bar 𝌆 baz’;
var bytes = utf8.encode(text);
var encoded = binaryToBase64(bytes);
console.log(encoded);
// Zm9vIMKpIGJhciDwnYyGIGJheg==
You might need to install the utf8 package, since it was removed from React Native on version 0.54:

npm install --save utf8
share improve this answer follow
edited Apr 4 '18 at 0:50

Rafa
7,44744 gold badges3131 silver badges57

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐