![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) Download Image (JPG, GIF, etc.) to Base64See more HTTP ExamplesDemonstrates 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) { BOOL success; HCkHttp http; HCkBinData bd; int statusCode; const char *base64_image_data; success = FALSE; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_Create(); CkHttp_putKeepResponseBody(http,TRUE); bd = CkBinData_Create(); success = CkHttp_DownloadBd(http,"https://www.chilkatsoft.com/images/starfish.jpg",bd); statusCode = CkHttp_getLastStatus(http); if (success == FALSE) { if (statusCode == 0) { // Unable to either send the request or get the response. printf("%s\n",CkHttp_lastErrorText(http)); } else { // We got a response, but the status code was not in the 200s printf("Response status code: %d\n",statusCode); // Examine the response body. printf("Response body:\n"); printf("%s\n",CkHttp_lastResponseBody(http)); } printf("Download failed.\n"); } else { printf("Download success, response status = %d\n",statusCode); 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); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.