Luben Luben - 1 year ago 92
iOS Question

iOS Amazon Cognito S3 metadata filenames

How do I get the metadata from my S3 bucket which contains the friendly filename of the file for display purposes.

For example in my table view I have a list of files in the following format:

private/eu-west-1:2dcdgv-des3-3res-fsgr-123456xxxxx/Demo Directory/bxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx

Now this part (the key) "bxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" should be something like myFile.jpg for example.

Answer Source

For those interested I solved it as follows:

-(NSString *)getFileMetaData:(NSString *)fKey
__block NSString *fName = @"";

AWSS3 *s3 = [AWSS3 defaultS3];
AWSS3HeadObjectRequest *request = [AWSS3HeadObjectRequest new];
request.bucket = @"myS3BucketName";
request.key = fKey;

[[[s3 headObject:request] continueWithBlock:^id _Nullable(AWSTask<AWSS3HeadObjectOutput *> * _Nonnull task)
    if(task.result.metadata != nil)
        //Do something with it...
        //Handle no data
    return nil;
}] waitUntilFinished];

return fName;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download