![]() |
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
(Objective-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.
#import <CkoHttp.h> #import <CkoBinData.h> #import <NSString.h> BOOL success = NO; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkoHttp *http = [[CkoHttp alloc] init]; http.KeepResponseBody = YES; CkoBinData *bd = [[CkoBinData alloc] init]; success = [http DownloadBd: @"https://www.chilkatsoft.com/images/starfish.jpg" binData: bd]; int statusCode = [http.LastStatus intValue]; if (success == NO) { if (statusCode == 0) { // Unable to either send the request or get the response. NSLog(@"%@",http.LastErrorText); } else { // We got a response, but the status code was not in the 200s NSLog(@"%@%d",@"Response status code: ",statusCode); // Examine the response body. NSLog(@"%@",@"Response body:"); NSLog(@"%@",http.LastResponseBody); } NSLog(@"%@",@"Download failed."); } else { NSLog(@"%@%d",@"Download success, response status = ",statusCode); NSString *base64_image_data = [bd GetEncoded: @"base64"]; NSLog(@"%@",@"image data in base64 format:"); NSLog(@"%@",base64_image_data); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.