Dart
Dart
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Get the contents of a file into a base64 encoded string:
final fac = CkFileAccess();
final String strBase64;
try {
strBase64 = fac.readBinaryToEncoded('c:/data/something.pdf', 'base64');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Now write the string to a file:
try {
fac.writeEntireTextFile('c:/data/something_pdf_base64.txt', strBase64, 'us-ascii', false);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Success!');
}