Если вы не можете позволить себе роскошь использовать ASI и / или застряли в AWSiOS SDK, это не сильно отличается:
/* borrowed from Maurício Linhares's answer */
NSString *secretAccessKey = @"my-secret-access-key";
NSString *accessKey = @"my-access-key";
NSString *bucket = @"my-bucket";
NSString *path = @"path/to/the/object";
/********************************************/
AmazonCredentials *credentials = [[AmazonCredentials alloc] initWithAccessKey: accessKey withSecretKey: secretAccessKey];
AmazonS3Client *connection = [[AmazonS3Client alloc] initWithCredentials: credentials];
S3GetObjectRequest *downloadRequest = [[[S3GetObjectRequest alloc] initWithKey:path withBucket: bucket] autorelease];
[downloadRequest setDelegate: self]; /* only needed for delegate (see below) */
S3GetObjectResponse *downloadResponse = [self.awsConnection getObject: downloadRequest];
Затем вы можете посмотреть downloadResponse.body
и downloadResponse.httpStatusCode
, предпочтительно в делегате:
-(void)request: (S3Request *)request didCompleteWithResponse: (S3Response *) response {
NSLog(@"Download finished (%d)",response.httpStatusCode);
/* do something with response.body and response.httpStatusCode */
/* if you have multiple requests, you can check request arg */
}