Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final bd = CkBinData();

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

  final b64Str = bd.getEncoded('base64');
  print(b64Str);

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