Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loBd
LOCAL lnStatusCode
LOCAL lcBase64_image_data

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')
loHttp.KeepResponseBody = 1

loBd = CreateObject('Chilkat.BinData')

lnSuccess = loHttp.DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg",loBd)
lnStatusCode = loHttp.LastStatus
IF (lnSuccess = 0) 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