(Visual FoxPro) Convert any File to Base64 (and back)
Demonstrates how to get the contents of any file as a base64 string, and then write it back.
LOCAL loBd
LOCAL lnSuccess
LOCAL lcB64Str
LOCAL loBd2
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData')
loBd = CreateObject('Chilkat.BinData')
* This example will load a PDF and return it as a base64 string.
lnSuccess = loBd.LoadFile("qa_data/pdf/helloWorld.pdf")
IF (lnSuccess <> 1) THEN
? "Failed to load file."
RELEASE loBd
CANCEL
ENDIF
lcB64Str = loBd.GetEncoded("base64")
? lcB64Str
* Now write the base64 string back to the binary PDF file:
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData')
loBd2 = CreateObject('Chilkat.BinData')
lnSuccess = loBd2.AppendEncoded(lcB64Str,"base64")
lnSuccess = loBd2.WriteFile("qa_output/helloWorld.pdf")
RELEASE loBd
RELEASE loBd2
|