Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoBd
    String sB64Str
2    Handle hoBd2

    Move False To iSuccess

    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End

    // This example will load a PDF and return it as a base64 string.
    Get ComLoadFile Of hoBd "qa_data/pdf/helloWorld.pdf" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Failed to load file."
        Procedure_Return
    End

    Get ComGetEncoded Of hoBd "base64" To sB64Str
    Showln sB64Str

    // Now write the base64 string back to the binary PDF file:
    Get Create (RefClass(cComChilkatBinData)) To hoBd2
    If (Not(IsComObjectCreated(hoBd2))) Begin
        Send CreateComObject of hoBd2
    End
    Get ComAppendEncoded Of hoBd2 sB64Str "base64" To iSuccess
    Get ComWriteFile Of hoBd2 "qa_output/helloWorld.pdf" To iSuccess


End_Procedure