ios – 在v2 AWS SDK中无法获得AWSS3PutObjectRequest,以在v1 SDK中复制S3PutObjectRequest

与新的Amazon SDK,https://github.com/aws/aws-sdk-ios-v2有问题

我只是试图将一个文件写入已经存在的s3 bucket.这是因为某些原因(即使它记录“成功”),我无法上班的代码.

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;
}];

再次感谢.

解决方法

AWSS3PutObjectRequest的主体属性需要是NSURL或NSData.如果您将Nsstring转换为NSData,就像您在v1代码片段中所做的那样,它应该可以工作.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...