Sample code for 30+ languages & platforms
Unicode C++

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 Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkBinDataW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;
    http.put_KeepResponseBody(true);

    CkBinDataW bd;

    success = http.DownloadBd(L"https://www.chilkatsoft.com/images/starfish.jpg",bd);
    int statusCode = http.get_LastStatus();
    if (success == false) {
        if (statusCode == 0) {
            //  Unable to either send the request or get the response.
            wprintf(L"%s\n",http.lastErrorText());
        }
        else {
            //  We got a response, but the status code was not in the 200s
            wprintf(L"Response status code: %d\n",statusCode);
            //  Examine the response body.
            wprintf(L"Response body:\n");
            wprintf(L"%s\n",http.lastResponseBody());
        }

        wprintf(L"Download failed.\n");

    }
    else {
        wprintf(L"Download success, response status = %d\n",statusCode);

        const wchar_t *base64_image_data = bd.getEncoded(L"base64");
        wprintf(L"image data in base64 format:\n");
        wprintf(L"%s\n",base64_image_data);
    }
    }