Проблемы с новым SDK Amazon, https://github.com/aws/aws-sdk-ios-v2
Я просто пытаюсь записать файл в ведро s3, которое уже существует. Вот код, который я не могу заставить работать по какой-либо причине (даже если он регистрирует "успех" ).
AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:@"KEY" secretKey:@"SECRET_KEY"];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
AWSS3 *s3 = [[AWSS3 alloc] initWithConfiguration:configuration];
AWSS3PutObjectRequest *logFile = [AWSS3PutObjectRequest alloc];
logFile.bucket = @"test";
logFile.key = @"file2";
logFile.contentType = @"text/plain";
logFile.body = @"this is a test";
[[s3 putObject:logFile] continueWithBlock:^id(BFTask *task) {
NSLog(@"Totally did it");
return nil;
}];
Предыдущий SDK (v1.x) работал, но я пытаюсь переключиться, потому что мне нравится функциональность фреймворков Bolts.
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:@"KEY" withSecretKey:@"SECRET_KEY"];
S3PutObjectRequest *logFile = [[S3PutObjectRequest alloc] initWithKey:@"file1" inBucket:@"test"];
logFile.contentType = @"text/plain";
NSString* myStuff = @"this is a test";
NSData* log = [myStuff dataUsingEncoding:NSUTF8StringEncoding];
logFile.data = log;
[s3 putObject:logFile];
Кто-нибудь играет с новым SDK, который может сказать мне, что я здесь делаю неправильно?
ОБНОВЛЕНИЕ - Новый фрагмент кода
AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:awsAccessKey secretKey:awsSecretKey];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
/* This section works but posts as text/xml
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
AWSS3TransferManagerUploadRequest *getLog = [AWSS3TransferManagerUploadRequest new];
*/
AWSS3 *transferManager = [[AWSS3 alloc] initWithConfiguration:configuration];
AWSS3PutObjectRequest *getLog = [AWSS3PutObjectRequest alloc];
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 upload:getLog] continueWithBlock:^id(BFTask *task) {
*/
[[transferManager putObject:getLog] continueWithBlock:^id(BFTask *task) {
if(task.error)
{
NSLog(@"Error: %@",task.error);
}
else
{
NSLog(@"Got here: %@", task.result);
}
return nil;
}];
Еще раз спасибо.