Sample code for 30+ languages & platforms
React Native

Convert any File to Base64 (and back)

Demonstrates how to get the contents of any file as a base64 string, and then write it back.

Chilkat React Native Downloads

React Native
import { BinData } from '@chilkat/react-native'

function chilkatExample() {
  const bd = new BinData();

  // This example will load a PDF and return it as a base64 string.
  try {
    bd.loadFile('qa_data/pdf/helloWorld.pdf');
  } catch {
    console.log('Failed to load file.');
    return;
  }

  const b64Str = bd.getEncoded('base64');
  console.log(b64Str);

  // Now write the base64 string back to the binary PDF file:
  const bd2 = new BinData();
  bd2.appendEncoded(b64Str, 'base64');
  bd2.writeFile('qa_output/helloWorld.pdf');
}