Sample code for 30+ languages & platforms
Lua

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.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local bd = chilkat.BinData.new()

local success = bd:load_file("qa_data/jpg/starfish.jpg")
if not success then
    print("Failed to load file.")
    return
end

print(bd:get_encoded("base64"))

-- If you want mult-line base64:
print("--")
print(bd:get_encoded("base64_mime"))

-- If you want hex..
print("--")
print(bd:get_encoded("hex"))

-- etc..