Objective-C
Objective-C
Initiate Resumable Upload Session
See more Google Cloud Storage Examples
Initiate a Google Cloud Storage resumable upload session..Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoHttpResponse.h>
BOOL success = NO;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
CkoJsonObject *jsonToken = [[CkoJsonObject alloc] init];
success = [jsonToken LoadFile: @"qa_data/tokens/googleCloudStorage.json"];
if (success == NO) {
NSLog(@"%@",jsonToken.LastErrorText);
return;
}
CkoJsonObject *jsonMetaData = [[CkoJsonObject alloc] init];
[jsonMetaData UpdateString: @"contentType" value: @"image/jpeg"];
// Adds the "Authorization: Bearer <access_token>" header..
http.AuthToken = [jsonToken StringOf: @"access_token"];
[http SetUrlVar: @"bucket_name" value: @"chilkat-bucket-b"];
[http SetUrlVar: @"object_name" value: @"penguins2.jpg"];
NSString *url = @"https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}";
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpJson: @"POST" url: url json: jsonMetaData contentType: @"application/json" response: resp];
if (success == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
int statusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"response status code = ",statusCode);
NSString *sessionUrl = @"";
if (statusCode != 200) {
NSLog(@"%@",resp.BodyStr);
}
else {
// The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
sessionUrl = [resp GetHeaderField: @"Location"];
NSLog(@"%@%@",@"Session URL = ",sessionUrl);
}