Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

local bd = chilkat.BinData.new()

-- This example will load a PDF and return it as a base64 string.
local success = bd:load_file("qa_data/pdf/helloWorld.pdf")
if not success then
    print("Failed to load file.")
    return
end

local b64Str = bd:get_encoded("base64")
print(b64Str)

-- Now write the base64 string back to the binary PDF file:
local bd2 = chilkat.BinData.new()
success = bd2:append_encoded(b64Str, "base64")
success = bd2:write_file("qa_output/helloWorld.pdf")