Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to S3 Using AWS SDK v2 (iOS)

I've been looking around and found no recent answer for a problem I'm having in uploading and downloading images from an iPhone application.

I'm using AWS SDK v2 and from what I have read and seen from sample S3 transfer codes, I need to start first using AWSCognitoCredentialsProvider.

AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider
                                                          credentialsWithRegionType:AWSRegionAPNortheast1
                                                          accountId:AWSAccountID
                                                          identityPoolId:CognitoPoolID
                                                          unauthRoleArn:CognitoRoleUnauth
                                                      authRoleArn:nil];

But the only information I have are: Access Key, Secret, Bucket name, and target directory

Related link I read is How do I download a file from S3 to an iPhone application?

But the code cannot compile even with the AWS SDK framework, and related frameworks are installed in the project.

How can this be done using only the AWS SDK v2?

Thank you.

like image 997
user3932017 Avatar asked Nov 29 '22 07:11

user3932017


2 Answers

For your convenience, I left the version in Swift

let credentialsProvider = AWSStaticCredentialsProvider(accessKey:"YOUR_ACCESS_KEY", secretKey: "YOUR_SECRET_KEY")
let defaultServiceConfiguration = AWSServiceConfiguration(region: AWSRegionType.EUWest1, credentialsProvider: credentialsProvider)
defaultServiceConfiguration.maxRetryCount = 5
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = defaultServiceConfiguration
let defaultS3 = AWSS3.defaultS3()

......

like image 36
Jibeex Avatar answered Dec 05 '22 04:12

Jibeex


You can also scrap using Cognito and use the Access Key/Secret:

AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:ACCESS_KEY_ID secretKey:SECRET_KEY];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest2
                                                                      credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

Make sure you use the region your bucket is actually in.

like image 96
CaptainStiggz Avatar answered Dec 05 '22 06:12

CaptainStiggz