Sample code for 30+ languages & platforms
CkPython

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

CkPython
import sys
import chilkat

success = False

bd = chilkat.CkBinData()

success = bd.LoadFile("qa_data/jpg/starfish.jpg")
if (success == False):
    print("Failed to load file.")
    sys.exit()

print(bd.getEncoded("base64"))

# If you want mult-line base64:
print("--")
print(bd.getEncoded("base64_mime"))

# If you want hex..
print("--")
print(bd.getEncoded("hex"))

# etc.