Sample code for 30+ languages & platforms
Lianja

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.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

loBd = createobject("CkBinData")

// This example will load a PDF and return it as a base64 string.
llSuccess = loBd.LoadFile("qa_data/pdf/helloWorld.pdf")
if (llSuccess <> .T.) then
    ? "Failed to load file."
    release loBd
    return
endif

lcB64Str = loBd.GetEncoded("base64")
? lcB64Str

// Now write the base64 string back to the binary PDF file:
loBd2 = createobject("CkBinData")
llSuccess = loBd2.AppendEncoded(lcB64Str,"base64")
llSuccess = loBd2.WriteFile("qa_output/helloWorld.pdf")


release loBd
release loBd2