[英]Amazon S3 iOS SDK v2 Upload with AWSAccessKeyId:Signature
I'm trying to upload file on S3 bucket and device is getting access information from another server (AWSAccessKeyId and Signature). 我正在尝试在S3存储桶上传文件,设备正在从另一台服务器(AWSAccessKeyId和Signature)获取访问信息。 Is it possible to upload file with AWS iOS SDK v2? 是否可以使用AWS iOS SDK v2上传文件? If not are there any chances to use another approach possible for iOS (eg. generate Pre-Signed URL and do the http post/put)? 如果没有机会使用另一种可能的iOS方法(例如生成预先签名的URL并进行http post / put)?
Right now I'm using this approach, but it's for access_key/access_secret: 现在我正在使用这种方法,但它适用于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'll be grateful for any ideas. 我会感激任何想法。
I recommend the following approach: 我推荐以下方法:
refresh
also should initiate the credentials retrieval process. 调用refresh
也应启动凭据检索过程。 defaultServiceConfiguration
or pass it to initWithConfiguration:
. 将您的凭证提供程序分配给defaultServiceConfiguration
或将其传递给initWithConfiguration:
. As a side note, when using initWithConfiguration:
, you need to manually retain a strong reference to an instance of AWSS3
. 作为旁注,当使用initWithConfiguration:
,您需要手动保留对AWSS3
实例的强引用。 Using defaultS3
will eliminate the need for this. 使用defaultS3
将消除对此的需要。
Hope this helps, 希望这可以帮助,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.