amazon web services - aws s3 sdk for iOS putObjectRegquest to "new" region not working -
first let me new ios/xcode aws.
i creating app writes data aws s3 bucket. app works when creating bucket , putting objects standard region. however, when change region singapore, app creates bucket - but, cannot put objects bucket , aws not produce error or exception of kind.
here code in question. commented code in createbucket method creates bucket in singapore. processgrandcentraldispatchupload method works standard region, not put objects singapore bucket.
- (void)createbucket { // create 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 image data specified s3 bucket , 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 uploaded." withtitle:@"upload completed"]; } [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:no]; }); } @catch (amazonserviceexception* asex) { nslog(@"putobject - amazonserviceexception - %@", asex); } @catch (amazonclientexception* acex) { nslog(@"putobject - amazonclientexception - %@", acex); } });
}
i 1 of maintainers of aws sdk ios. i'm sorry you're encountering difficulties.
if bucket name contains non alpha numeric characters may need set endpoint of amazon s3 client region of bucket.
amazons3client *s3 = [[amazons3client alloc] initwithcredentialsprovider:provider]; s3.endpoint = [amazonendpoints s3endpoint:ap_southeast_1];
you can turn on verbose logging in application see raw responses service while using sdk. if see errors coming not being captured, please let know.
[amazonlogger verboselogging];
a couple things note code may want consider:
- once bucket created, no longer need call create bucket. may want consider removing
s3createbucketrequest/s3createbucketresponse
application. - s3 bucket naming unique across regions. if bucket created in standard cannot create in singapore without first deleting bucket in standard.
- you seem mixing both exception , error handling in code. please see our blog post on how control exception handling in sdk.
Comments
Post a Comment