Sample code for 30+ languages & platforms
Lianja

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

Lianja
llSuccess = .F.

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

loHttp = createobject("CkHttp")
loHttp.KeepResponseBody = .T.

loBd = createobject("CkBinData")

llSuccess = loHttp.DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg",loBd)
lnStatusCode = loHttp.LastStatus
if (llSuccess = .F.) then
    if (lnStatusCode = 0) then
        // Unable to either send the request or get the response.
        ? loHttp.LastErrorText
    else
        // We got a response, but the status code was not in the 200s
        ? "Response status code: " + str(lnStatusCode)
        // Examine the response body.
        ? "Response body:"
        ? loHttp.LastResponseBody
    endif

    ? "Download failed."

else
    ? "Download success, response status = " + str(lnStatusCode)

    lcBase64_image_data = loBd.GetEncoded("base64")
    ? "image data in base64 format:"
    ? lcBase64_image_data
endif



release loHttp
release loBd