(Unicode C) Download Image (JPG, GIF, etc.) to Base64
Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.
#include <C_CkHttpW.h>
#include <C_CkBinDataW.h>
void ChilkatSample(void)
{
HCkHttpW http;
HCkBinDataW bd;
BOOL success;
const wchar_t *base64_image_data;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
bd = CkBinDataW_Create();
success = CkHttpW_DownloadBd(http,L"https://www.chilkatsoft.com/images/starfish.jpg",bd);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkBinDataW_Dispose(bd);
return;
}
base64_image_data = CkBinDataW_getEncoded(bd,L"base64");
wprintf(L"image data in base64 format:\n");
wprintf(L"%s\n",base64_image_data);
CkHttpW_Dispose(http);
CkBinDataW_Dispose(bd);
}
|