Sample code for 30+ languages & platforms
Rust

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

Rust

let bd = chilkat::BinData::new();

// This example will load a PDF and return it as a base64 string.
if bd.load_file("qa_data/pdf/helloWorld.pdf").is_err() {
    println!("Failed to load file.");
    return;
}

let b64_str = bd.get_encoded("base64").unwrap_or_default();
println!("{}", b64_str);

// Now write the base64 string back to the binary PDF file:
let bd2 = chilkat::BinData::new();
let _ = bd2.append_encoded(&b64_str, "base64").is_ok();
let _ = bd2.write_file("qa_output/helloWorld.pdf").is_ok();