Sample code for 30+ languages & platforms
JavaScript

Get Contents of File as Base64

See more Encryption Examples

Demonstrates how to read the contents of a file and convert to a base64 string.
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;

var bd = new CkBinData();

success = bd.LoadFile("qa_data/jpg/starfish.jpg");
if (success == false) {
    console.log("Failed to load file.");
    return;
}

console.log(bd.GetEncoded("base64"));

// If you want mult-line base64:
console.log("--");
console.log(bd.GetEncoded("base64_mime"));

// If you want hex..
console.log("--");
console.log(bd.GetEncoded("hex"));

// etc.