(DataFlex) Base64 Encode a File
DataFlex to Base64 encode the contents of a file.
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoFac
String sStrBase64
Boolean iSuccess
String sTemp1
Boolean bTemp1
// Get the contents of a file into a base64 encoded string:
Get Create (RefClass(cComCkFileAccess)) To hoFac
If (Not(IsComObjectCreated(hoFac))) Begin
Send CreateComObject of hoFac
End
Get ComReadBinaryToEncoded Of hoFac "c:/data/something.pdf" "base64" To sStrBase64
Get ComLastMethodSuccess Of hoFac To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoFac To sTemp1
Showln sTemp1
Procedure_Return
End
// Now write the string to a file:
Get ComWriteEntireTextFile Of hoFac "c:/data/something_pdf_base64.txt" sStrBase64 "us-ascii" False To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoFac To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Success!"
End_Procedure
|