With the AWSiOS SDK how do you do a HEAD request on an S3 object?

二次信任 提交于 2019-12-10 11:14:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!