AWS S3 SDK为iOS putObjectRegquest到"新"区域不工作 [英] aws s3 sdk for iOS putObjectRegquest to "new" region not working

查看:278
本文介绍了AWS S3 SDK为iOS putObjectRegquest到"新"区域不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说,我是新的IOS / X code以及AWS。

first let me say that I am new ios/xcode as well as AWS.

我创建一个应用程序,将数据写入到AWS S3桶。创造一个水桶,并把对象的美国标准地区时,应用程序的工作原理。然而,当我的区域改为新加坡,应用程序创建的水桶成功 - 但是,我不能把物体插入水桶和AWS不会产生任何的错误或异常

I am creating an app that writes data to an AWS S3 bucket. The app works when creating a bucket and putting objects to the US Standard Region. However, when I change the region to Singapore, the app creates the bucket successfully - but, I cannot put objects into the bucket and AWS does not produce an error or exception of any kind.

下面是code问题。该评论code在createBucket方法成功地创建了在新加坡的水桶。该processGrandCentralDispatchUpload方法是作品为美国标准区域,但不把对象给我的新加坡桶。

Here is the code in question. The commented code in the createBucket method successfully creates a bucket in Singapore. The processGrandCentralDispatchUpload method is works for the US Standard region, but does not put objects to my Singapore bucket.

- (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);
    }

});

}

推荐答案

我是AWS SDK为iOS的维护者之一。对不起,你遇到的困难。

I am one of the maintainers of the AWS SDK for iOS. I'm sorry you're encountering difficulties.

如果你的水桶名称包含非字母数字字符,你可能需要在Amazon S3的客户端的端点设置为您的桶的区域。

If your bucket name contains non alpha numeric characters you may need to set the endpoint of the Amazon S3 client to the region of your bucket.

AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithCredentialsProvider:provider];
s3.endpoint = [AmazonEndpoints s3Endpoint:AP_SOUTHEAST_1];

您还可以打开详细日志记录在您的应用程序,同时使用SDK从服务看的原始响应。如果你看到的错误来了未被捕获回来,请告诉我们。

You can also turn on verbose logging in your application to see the raw responses from the service while using the SDK. If you do see errors coming back that are not being captured, please let us know.

[AmazonLogger verboseLogging];

一对夫妇的事情,我会注意到你的code,你可能还需要考虑:

A couple things I will note about your code that you may also want to consider:

  • 一旦桶被创建,您不再需要调用创建桶。您可能需要考虑您的应用程序删除 S3CreateBucketRequest / S3CreateBucketResponse
  • 在S3存储桶的命名是在所有地区唯一的。如果桶是在美国创建的标准,那么你不能在新加坡不先删除在美国标准桶创建它。
  • 您似乎在code可混合两种异常和错误处理。请参阅<一href="http://mobile.awsblog.com/post/Tx2PZV371MJJHUG/How-Not-to-Throw-Exceptions-with-the-AWS-SDK-for-iOS"相对=nofollow>我们的博客帖子如何控制异常处理的SDK。
  • Once the bucket is created, you no longer need to call create bucket. You may want to consider removing the S3CreateBucketRequest/S3CreateBucketResponse from your application.
  • S3 bucket naming is unique across all regions. If the bucket was created in US Standard then you cannot create it in Singapore without first deleting the bucket in US Standard.
  • You seem to be mixing both exception and error handling in your code. Please see our blog post on how to control exception handling in the SDK.

这篇关于AWS S3 SDK为iOS putObjectRegquest到&QUOT;新&QUOT;区域不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆