Ben Ben - 1 year ago 103
iOS Question

Generating a signed URL for AWS S3

I'm trying to create a signed url for AWS S3, i just want the URL for a file in my bucket, i don't want to use it for upload/download.

I've tried AFNetworking, following the steps on Amazons documentation and am now using the AWS iOS SDK.

So far i have this:

AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:@"Access Key" secretKey:@"secret key"];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest2 credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
AWSS3PreSignedURLBuilder * urlBuilder = [[AWSS3PreSignedURLBuilder alloc] initWithConfiguration:configuration];

AWSS3GetPreSignedURLRequest *preSignedURLRequest = [AWSS3GetPreSignedURLRequest new];
preSignedURLRequest.bucket = @"bucket-name";
preSignedURLRequest.key = @"/filename";
preSignedURLRequest.HTTPMethod = AWSHTTPMethodGET;
preSignedURLRequest.expires = [NSDate dateWithTimeIntervalSinceNow:3600];

NSURL *preSignedURL = [urlBuilder getPreSignedURL:preSignedURLRequest];

NSLog(@"%@", preSignedURL);

I'm getting a lot of errors about the code being depreciated, but more importantly i Know that the method getPreSignedURL returns a type (AWSTask *), my question is how to turn a AWSTask into the signed url?

Also i don't plan on leaving the keys in my code this is just temporary for testing.

If anyone could help me find how to get the preSignedURL that'd be a great help.

Answer Source

Have you tried S3BackgroundTransfer-Sample? It should help you get started.

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