首先让我说我是新的 ios/xcode 以及 AWS。
我正在创建一个将数据写入 AWS S3 存储桶的应用程序。该应用程序在创建存储桶并将对象放入美国标准区域时工作。但是,当我将区域更改为新加坡时,应用程序成功创建了存储桶 - 但是,我无法将对象放入存储桶中,AWS 不会产生任何类型的错误或异常。
这是有问题的代码。createBucket 方法中的注释代码在新加坡成功创建了一个bucket。processGrandCentralDispatchUpload 方法适用于美国标准区域,但不会将对象放入我的新加坡存储桶。
- (void)createBucket
{
// Create the bucket.
@try {
//S3Region *region = [[S3Region alloc] initWithStringValue:kS3RegionAPSoutheast1];
//S3CreateBucketRequest *createBucketRequest = [[S3CreateBucketRequest alloc] initWithName:[Constants S3Bucket] andRegion:region];
S3CreateBucketRequest *createBucketRequest = [[S3CreateBucketRequest alloc] initWithName:[Constants S3Bucket]];
S3CreateBucketResponse *createBucketResponse = [self.s3 createBucket:createBucketRequest];
NSLog(@"create bucket response: %@", createBucketResponse.error);
if(createBucketResponse.error != nil)
{
NSLog(@"Error: %@", createBucketResponse.error);
}
}
@catch (AmazonServiceException* asex) {
NSLog(@"putObject - AmazonServiceException - %@", asex);
}
@catch (AmazonClientException* acex) {
NSLog(@"putObject - AmazonClientException - %@", acex);
}
}
- (void)processGrandCentralDispatchUpload:(NSData *)jsonData withTimestamp:(int)timestamp
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
UserData * user = [[[DataStore defaultStore] user] objectAtIndex:0];
NSString * dateKeyComponent = [self putRequestDateComponent:timestamp];
objectName = [NSString stringWithFormat:@"%@/%@/%@", user.email, user.uniqueIdentifier, dateKeyComponent];
S3PutObjectRequest *putObjectRequest = [[S3PutObjectRequest alloc] initWithKey:objectName
inBucket:[Constants S3Bucket]];
putObjectRequest.contentType = @"data/json";
putObjectRequest.data = jsonData;
// Put the image data into the specified s3 bucket and object.
@try {
S3PutObjectResponse *putObjectResponse = [self.s3 putObject:putObjectRequest];
dispatch_async(dispatch_get_main_queue(), ^{
if(putObjectResponse.error != nil)
{
NSLog(@"Error: %@", putObjectResponse.error);
[self showAlertMessage:[putObjectResponse.error.userInfo objectForKey:@"message"] withTitle:@"Upload Error"];
}
else
{
//[self showAlertMessage:@"The data was successfully uploaded." withTitle:@"Upload Completed"];
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
}
@catch (AmazonServiceException* asex) {
NSLog(@"putObject - AmazonServiceException - %@", asex);
}
@catch (AmazonClientException* acex) {
NSLog(@"putObject - AmazonClientException - %@", acex);
}
});
}