Sample code for 30+ languages & platforms
JavaScript

Base64 Encode a File

_LANGUAGE_ to Base64 encode the contents of a file.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

// Get the contents of a file into a base64 encoded string:
var fac = new CkFileAccess();
var strBase64 = fac.ReadBinaryToEncoded("c:/data/something.pdf","base64");
if (fac.LastMethodSuccess !== true) {
    console.log(fac.LastErrorText);
    return;
}

// Now write the string to a file:
success = fac.WriteEntireTextFile("c:/data/something_pdf_base64.txt",strBase64,"us-ascii",false);
if (success !== true) {
    console.log(fac.LastErrorText);
    return;
}

console.log("Success!");