Amazon S3 iOS SDK v2 Download Using AWSAccessKeyId: Signature

I try to upload a file to an S3 bucket and the device receives access information from another server (AWSAccessKeyId and Signature). Can I upload a file using AWS iOS SDK v2? If not, is there any chance of using a different approach for iOS (for example, creating a pre-signed URL and making an http / put message)?

I am using this approach now, but for access_key / access_secret:

AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:awsAccessKey secretKey:awsSecretKey]; AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider]; [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration; AWSS3 *transferManager = [[AWSS3 alloc] initWithConfiguration:configuration]; AWSS3PutObjectRequest *getLog = [[AWSS3PutObjectRequest alloc] init]; getLog.bucket = awsS3Bucket; getLog.key = awsS3FileNameString; getLog.contentType = @"text/plain"; NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *fileName = [documentsDirectory stringByAppendingPathComponent:logFileName]; long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileName error:nil][NSFileSize] longLongValue]; getLog.body = [NSURL fileURLWithPath:fileName]; getLog.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize]; [[transferManager putObject:getLog] continueWithBlock:^id(BFTask *task) { if(task.error) { NSLog(@"Error: %@",task.error); } else { NSLog(@"Got here: %@", task.result); } return nil; }]; 

I would be grateful for any ideas.

+6
source share
1 answer

I recommend the following approach:

  • Create a passkey , secret key and token on your server. You have many language options, including Java, .NET, PHP, Ruby, Python, and Node.js.
  • Deploy your own credential provider by running AWSCredentialsProvider . This credential provider must:
    • Retrieve the passkey, secret key, and session key from your server.
    • Keep them until they expire.
    • Return credentials on request.
    • If they expired, retrieve them from your server.
    • The refresh call should also initiate the credential retrieval process.
  • Assign your credential provider to defaultServiceConfiguration or pass it to initWithConfiguration:

As a side note, when using initWithConfiguration: you need to manually save the link to the AWSS3 instance. Using defaultS3 will eliminate the need for this.

Hope this helps,

+3
source

Source: https://habr.com/ru/post/973073/


All Articles