(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_CkHttp.h>
#include <C_CkBinData.h>
void ChilkatSample(void)
{
HCkHttp http;
HCkBinData bd;
BOOL success;
const char *base64_image_data;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
bd = CkBinData_Create();
success = CkHttp_DownloadBd(http,"https://www.chilkatsoft.com/images/starfish.jpg",bd);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkBinData_Dispose(bd);
return;
}
base64_image_data = CkBinData_getEncoded(bd,"base64");
printf("image data in base64 format:\n");
printf("%s\n",base64_image_data);
CkHttp_Dispose(http);
CkBinData_Dispose(bd);
}
|