0
首先讓我說,我是新的IOS /的Xcode以及AWS。AWS S3 SDK適用於iOS putObjectRegquest到「新」區不工作
我創建一個AWS S3存儲寫入數據的應用程序。該應用程序在創建存儲桶並將對象放入美國標準區域時起作用。但是,當我將該地區更改爲新加坡時,應用程序會成功創建存儲區 - 但我無法將對象放入存儲區,AWS不會產生任何錯誤或例外。
這裏是有問題的代碼。 createBucket方法中的註釋代碼在新加坡成功創建了一個存儲桶。 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);
}
});
}
我在1.7.0上,最近剛剛意識到(在我的應用程序中添加錯誤日誌記錄後)我的'S3.putObject'偶爾會失敗並拋出一個異常。我剛剛升級到1.7.1,並根據您的建議添加了「端點」,並希望能夠修復它。 (是的,我的存儲桶名稱確實包含破折號) – pixelfreak
沒有,1.7.1沒有解決它。我仍然得到異常,並且它不能被try/catch捕獲,可能是因爲它運行在另一個線程上。在這一點上,我只是暫緩使用這個SDK,直到有一個確定的修復:( – pixelfreak