Ruby
Ruby
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 Ruby Downloads
require 'chilkat'
success = false
bd = Chilkat::CkBinData.new()
success = bd.LoadFile("qa_data/jpg/starfish.jpg")
if (success == false)
print "Failed to load file." + "\n";
exit
end
print bd.getEncoded("base64") + "\n";
# If you want mult-line base64:
print "--" + "\n";
print bd.getEncoded("base64_mime") + "\n";
# If you want hex..
print "--" + "\n";
print bd.getEncoded("hex") + "\n";
# etc.