![]() |
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
(Unicode 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 <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); } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.