Chilkat2-Python
Chilkat2-Python
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Chilkat2-Python Downloads
import sys
import chilkat2
success = False
# Get the contents of a file into a base64 encoded string:
fac = chilkat2.FileAccess()
strBase64 = fac.ReadBinaryToEncoded("c:/data/something.pdf","base64")
if (fac.LastMethodSuccess != True):
print(fac.LastErrorText)
sys.exit()
# Now write the string to a file:
success = fac.WriteEntireTextFile("c:/data/something_pdf_base64.txt",strBase64,"us-ascii",False)
if (success != True):
print(fac.LastErrorText)
sys.exit()
print("Success!")