(Objective-C) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
#import <CkoHttp.h>
#import <NSString.h>
#import <CkoBinData.h>
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
http.AwsAccessKey = @"AWS_ACCESS_KEY";
http.AwsSecretKey = @"AWS_SECRET_KEY";
NSString *bucketName = @"chilkat.qa";
NSString *objectName = @"images/sea_creatures/starfish.jpg";
NSString *localFilePath = @"qa_data/jpg/starfish.jpg";
NSString *contentType = @"image/jpg";
CkoBinData *jpgData = [[CkoBinData alloc] init];
BOOL success = [jpgData LoadFile: localFilePath];
if (!success) {
NSLog(@"%@%@",@"Failed to load ",localFilePath);
return;
}
NSData jpgBytes;
jpgBytes = [jpgData GetBinary];
success = [http S3_UploadBytes: jpgBytes contentType: contentType bucketName: bucketName objectName: objectName];
if (success != YES) {
NSLog(@"%@",http.LastErrorText);
return;
}
NSLog(@"%@",@"Success. File uploaded.");
|