Feb 012012
 

This may not be useful to others, but it bothered me quite some time, so I’d like to write it down in case some others stuck at the same place as I did.

getMetadataForKey calls from aws-ios-sdk, actually it:

  1. returns user defined meta data, nothing to do with s3’s meta data
  2. the key used here will be prepended a “x-aws-meta-“, that is, in aws console, we will see a meta data entry keyed with “x-aws-meta-hahaha”, but in ios app you need to use “hahaha” to get the value

some other interesting stuffs … don’t use S3GetObjectRequest/Response call to get object’s header information, as it will indeed download the object. Instead, you should use S3GetObjectMetadataRequest/Response.

To get “Expiry Date” and  “Lifecycle Rule” information as they are shown on aws console, you need to use response”s valueForHTTPHeaderField method with key “x-amz-expiration”, the parse it … I guess there should be something more easier but havenn’t figured out how. Both “expiry-date” and “rule-id” are there so you can use them, note that they can be empty so better prepare for that.

  3 Responses to “aws s3 development tips”

  1. Hi. I found your blog post when searching for a solution for my problem. Your post help me in finding the right direction but I’m still stuck trying to get the etag of the file without having to download it first.
    Using the S3GetObjectMetadataRequest seems to be the right way, buuut, trying to initialize the object gives me a serious warning, and later after getting the metadata response the object is empty.
    The initializing is this:
    S3GetObjectMetadataRequest *metadata = [[S3GetObjectMetadataRequest alloc] initWithKey:key withBucket:bucket];

    and the warning is:
    Incompatible Objective-C types initializing ‘struct S3GetObjectRequest *’, expected ‘struct S3GetObjectMetadataRequest *’

    using cast doesn’t fix it.

    I would be very glad to you if you could help me finding a solution.
    Thanks you advance and congrats for your blog.

  2. Are you sure you got the right line for the error? I feel like that you were trying to use “metadata” to make a call and that causes the problem.

    And I have almost exacxtly the same code as you do (for this line) without any problem, and I pasted here in case you want to do a double check:

    S3GetObjectMetadataRequest * getObjectMetadataRequest = [[S3GetObjectMetadataRequest alloc] initWithKey:objectName withBucket:bucketName];

    Or maybe you want to post some more code plus errors so that we can look into.

  3. Hi Hang!
    Thanks for the response.

    It is right, and I was doing it the right way also. The problem was in Amazon permissions. But the strange warning keeps showing. Maybe its a version incompatibility bug, or a pre-compiler error, don’t know. The important think is that its working now 🙂

Sorry, the comment form is closed at this time.