我一直在研究这个问题很长一段时间没有运气。我按照http://aws.amazon.com/articles/3002109349624271
使用Amazon S3 iOS上传SDK 症状:
可以创建一个桶,不会上传图像。 S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
返回nil。
这是我的代码: 在viewDidLoad
中self.s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
self.s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
尝试使用和不使用端点;根据{{3}}
添加稍后在同一视图控制器中调用的上传函数:
...
NSData *data = UIImageJPEGRepresentation(newImage, 0.9);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// Upload image data. Remember to set the content type.
S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:PICTURE_NAME
inBucket:PICTURE_BUCKET];
por.contentType = @"image/jpeg";
por.data = data;
por.delegate = self;
// Put the image data into the specified s3 bucket and object.
S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_async(queue, ^{
if(putObjectResponse.error != nil)
{
NSLog(@"Error: %@", putObjectResponse.error);
[self showAlertMessage:[putObjectResponse.error.userInfo objectForKey:@"message"] withTitle:@"Upload Error"];
}
});
NSLog(@"image PUT to amazon");
// Set the content type so that the browser will treat the URL as an image.
S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
override.contentType = @"image/jpeg";
// Request a pre-signed URL to picture that has been uploaded.
S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
gpsur.key = PICTURE_NAME;
gpsur.bucket = PICTURE_BUCKET;
gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 7200]; // Added an hour's worth of seconds to the current time.
gpsur.responseHeaderOverrides = override;
// Get the URL
NSError *error;
NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];
NSString *imageURL = url.absoluteString;
NSLog(@"%@",imageURL);
});
永远不会抛出错误,如果我转到URL,它只是说“指定的密钥不存在。”
如果您有任何想法,请告诉我!这让我发疯了!