Sample code for 30+ languages & platforms
DataFlex

Download Image (JPG, GIF, etc.) to Base64

See more HTTP Examples

Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vBd
    Handle hoBd
    Integer iStatusCode
    String sBase64_image_data
    String sTemp1

    Move False To iSuccess

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComKeepResponseBody Of hoHttp To True

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

    Get pvComObject of hoBd to vBd
    Get ComDownloadBd Of hoHttp "https://www.chilkatsoft.com/images/starfish.jpg" vBd To iSuccess
    Get ComLastStatus Of hoHttp To iStatusCode
    If (iSuccess = False) Begin
        If (iStatusCode = 0) Begin
            // Unable to either send the request or get the response.
            Get ComLastErrorText Of hoHttp To sTemp1
            Showln sTemp1
        End
        Else Begin
            // We got a response, but the status code was not in the 200s
            Showln "Response status code: " iStatusCode
            // Examine the response body.
            Showln "Response body:"
            Get ComLastResponseBody Of hoHttp To sTemp1
            Showln sTemp1
        End

        Showln "Download failed."

    End
    Else Begin
        Showln "Download success, response status = " iStatusCode

        Get ComGetEncoded Of hoBd "base64" To sBase64_image_data
        Showln "image data in base64 format:"
        Showln sBase64_image_data
    End



End_Procedure