How to convert string to base64 in react native?

react-native download image base64
convert byte array to base64 string react native
convert pdf to base64 react native
how to convert image url to base64 string in react native
expo base64
base64 decoding react native

I'm looking for a way to convert a string to Base64 in react native such as btoa().

btoa() is only working when developer tools are open.

Thanks, Eranbo

btoa() is only working when developer tools are open

It`s because in debug mode and without it code work in different js engines (V8 and coreJS). I guess (if it really did not work), the coreJS has not btoa implementation.

Use third party libs for it. For example npm:js-base64.

react-native-base64, Install npm install --save react-native-base64. How to use: import base64 from '​react-native-base64' base64.encode('Some string to encode  How to encode a string into in base64 format in react native. In this article we will learn How to encode a string into in base64 format in react native. For this purpose we will install ‘buffer’ module in this way either using yarn or npm install command – npm install buffer Don’t forget to import this inside your js file –

rn-fetch-blob allow you to do the conversion in native code :

export const blobToBase64 = async (data, encoding = 'base64') => fs.readFile(data, encoding);

How to convert a file into base64 string in react native?, Hi all, I am trying to convert a file (pdf, word, excel, image, text) into a base64 string in react-native. After converting into a base64 string I just  I am trying to using React-Native-Camera to capture an image and upload to the server, the captured response only provide base64 image and relative uri path to the system's cache. I used to turn the image to a blob in websites using packages like blob-util, which doesn't work on React-native.

As I mentioned in the comment above I ended up writing my self base64 encoder decoder. I've uploaded it to npm and you are all welcome to use it. Enjoy, eranbo

Using Base64 encode/decode in a React Native/Expo app , I can't believe that I can't easily encode and decode Base64 string in React Native without pulling my hair. I'm using Expo to manage my  Problem. I created a social media app with expo's react native, and wanted to add the ability to upload images. Since expo won't let you convert a file to a blob to upload, I just uploaded the base64 image data as a string to the server database.

You can do it in vanilla js like follow :

export const UriToBase64 = blob => {
  return new Promise((resolve, reject) => {
    if (window.FileReader) {
      const reader = new window.FileReader();
      if (blob && blob.type.match('image.*')) {
        reader.onerror = reject;
      } else {
        reject(new Error('Bad type, must be image'));
      reader.onloadend = () => resolve(reader.result);
    } else {
      reject(new Error('No FileReader on window'));

export default {

How to encode a string into in base64 format in react native, How to convert any parameter in base64 string in react native, encoding in react native, base 64 string in react native, Conversion into base64  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 ?

Base64 encoding/decoding · Issue #1158 · facebook/react-native , If you just want to encode data on the JS side, you should just be able to pull in any 3rd party base64 module (here's one:  I'm building a react native app that needs to store images at base64 string format for offline viewing capabilities. What library / function would give me the best result to store the image as bas

eranbo/react-native-base64: Base64 encoding and , Base64 encoding and decoding helping util. Created for import base64 from '​react-native-base64' base64.encode('Some string to encode to base64');  I have used react-native-image-picker and now I select image from the Photo library. To send the that image to API I have to convert it first into base64 and then into byte array. I have the filepa

How to Encode and Decode Strings with Base64 in JavaScript , Updated November 26, 2018: Fixed the broken code thanks to commenters fixes. Encoding and decoding a string in Base64 with JavaScript  The problem with that is obviously that you're sending the image data from native to JS (as base64 strings) and then back again via AsyncStorage, which is hugely wasteful. The problem is that we don't currently have an API for saving uris directly to the file system on the native side without transferring the data to and from JS.

  • Thanks @kirill I ended up writing my own encode decode service class.
  • Maybe I'll upload it to npm
  • Yeah, but my package is much simpler with no need to run link command on the react native cli and the most important stuff it's small, one file, easy to understand change and use
  • Hi Alex Levy, in React-Native there is no window
  • Sorry it's because I use React Native Web