Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oBd
LOCAL nStatusCode
LOCAL cBase64_image_data

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")
oHttp:KeepResponseBody := 1

oBd := CreateObject("Chilkat.BinData")

nSuccess := oHttp:DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg", oBd)
nStatusCode := oHttp:LastStatus
IF (nSuccess == 0)
    IF (nStatusCode == 0)
        //  Unable to either send the request or get the response.
        ? oHttp:LastErrorText
    ELSE
        //  We got a response, but the status code was not in the 200s
        ? "Response status code: " + Str(nStatusCode)
        //  Examine the response body.
        ? "Response body:"
        ? oHttp:LastResponseBody
    ENDIF

    ? "Download failed."

ELSE
    ? "Download success, response status = " + Str(nStatusCode)

    cBase64_image_data := oBd:GetEncoded("base64")
    ? "image data in base64 format:"
    ? cBase64_image_data
ENDIF

oHttp:destroy()
oBd:destroy()