问题
I'm looking to use the SDK (can't use ASI) to do HEAD requests on objects before I download them to determine the size. Is there a provided way to do this I'm overlooking, or am I forced to build up my own S3Request, setting the httpMethod property to be "HEAD" and passing the constructed S3Request to the invoke: method of AmazonS3Client ?
Building the request myself gets a little dicey as I'm using federated users, so I wanted to make sure I wasn't duplicating something I had overlooked.
回答1:
I am a maintainer of the AWS SDK for iOS. You can also use the S3GetObjectMetadataRequest to do the same thing.
S3GetObjectMetadataRequest *request =
[[S3GetObjectMetadataRequest alloc] initWithKey:FILE_NAME withBucket:BUCKET_NAME];
S3GetObjectMetadataResponse *response = [s3 getObjectMetadata:request];
int64_t fileSize = response.contentLength;
回答2:
Turned out to be fairly straight forward, but still wondering if there's a more accepted way of doing a HEAD.
S3GetObjectRequest *headRequest = [[[S3GetObjectRequest alloc] initWithKey:keyname withBucket: [bucketname]] autorelease];
headRequest.httpMethod = @"HEAD";
S3Response *headResponse = [[S3Response alloc] init];
headResponse = [self.awsConnection invoke:headRequest];
来源:https://stackoverflow.com/questions/8530215/with-the-awsios-sdk-how-do-you-do-a-head-request-on-an-s3-object