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.
source share