React Native
React Native
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat React Native Downloads
import { FileAccess } from '@chilkat/react-native'
function chilkatExample() {
// Get the contents of a file into a base64 encoded string:
const fac = new FileAccess();
let strBase64: string;
try {
strBase64 = fac.readBinaryToEncoded('c:/data/something.pdf', 'base64');
} catch {
console.log(fac.lastErrorText);
return;
}
// Now write the string to a file:
try {
fac.writeEntireTextFile('c:/data/something_pdf_base64.txt', strBase64, 'us-ascii', false);
} catch {
console.log(fac.lastErrorText);
return;
}
console.log('Success!');
}