ios - AWS S3 Upload works on Simulator but not on Device -


i'm encountering interesting problem. trying upload file aws s3, works when run on simulator, when run on connected device (debug mode). when package app , deploy device, doesn't work. keep getting "request timed out".

this code,

- (void)uploadfileatpath:(nsstring *)filepath completionhandler:(void (^)(nsstring *, nserror *))handler {     nsstring *filename = [filepath lastpathcomponent];     awss3getpresignedurlrequest *getpresignedurlrequest = [awss3getpresignedurlrequest new];     getpresignedurlrequest.bucket = self.bucketname;     getpresignedurlrequest.key = filename;     getpresignedurlrequest.httpmethod = awshttpmethodput;     getpresignedurlrequest.expires = [nsdate datewithtimeintervalsincenow:3600];      nsstring *filecontenttypestr = @"application/zip";     getpresignedurlrequest.contenttype = filecontenttypestr;      [[[awss3presignedurlbuilder defaults3presignedurlbuilder] getpresignedurl:getpresignedurlrequest]      continuewithblock:^id(awstask *task) {           if (task.error) {              nslog(@"error: %@",task.error);          } else {               nsurl *presignedurl = task.result;               nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:presignedurl];              request.cachepolicy = nsurlrequestreloadignoringlocalcachedata;              [request sethttpmethod:@"put"];              [request setvalue:filecontenttypestr forhttpheaderfield:@"content-type"];              [request sethttpbody:[nsdata datawithcontentsoffile:filepath]];               nsurlsessionconfiguration* config = [nsurlsessionconfiguration defaultsessionconfiguration];              nsurlsession * session = [nsurlsession sessionwithconfiguration:config delegate:nil delegatequeue:nil];               nsurlsessiondatatask* uploadtask = [session datataskwithrequest:request completionhandler:^(nsdata * _nullable data, nsurlresponse * _nullable response, nserror * _nullable error) {                  if (error) {                      nslog(@"url session task failed: %@", [error localizeddescription]);                  }                  else {                      nslog(@"url session task succeeded: http %ld", ((nshttpurlresponse*)response).statuscode);                   }                  handler([[((nshttpurlresponse*)response).url.absolutestring componentsseparatedbystring:@"?"] firstobject], error);               }];              [uploadtask resume];          }           return nil;      }]; } 

and error (obfuscated sensitive parts) -

error: request timed out.,  userinfo: {    nserrorfailingurlkey = "https://s3.amazonaws.com/bucketname/file-2-10-2015-10-13pm.zip?x-amz-algorithm=aws4-hmac-sha256&x-amz-credential=akiaihy7kkhblyopmtpa%2f20151003%2fus-east-1%2fs3%2faws4_request&x-amz-date=20151003t051306z&x-amz-expires=3599&x-amz-signedheaders=content-type%3bhost&x-amz-signature=504e1f5083116as09dc6a04c3b4152816a8d9e8bccff8f4ea0cbss9fcdc21eac";    nserrorfailingurlstringkey = "https://s3.amazonaws.com/bucketname/file-2-10-2015-10-13pm.zip?x-amz-algorithm=aws4-hmac-sha256&x-amz-credential=akiaihy7kkhblyopmtpa%2f20151003%2fus-east-1%2fs3%2faws4_request&x-amz-date=20151003t051306z&x-amz-expires=3599&x-amz-signedheaders=content-type%3bhost&x-amz-signature=504e1f5083116as09dc6a04c3b4152816a8d9e8bccff8f4ea0cbss9fcdc21eac";    nslocalizeddescription = "the request timed out.";    nsunderlyingerror = "error domain=kcferrordomaincfnetwork code=-1001 \"(null)\" userinfo={_kcfstreamerrordomainkey=4, _kcfstreamerrorcodekey=-2102}";    "_kcfstreamerrorcodekey" = "-2102";    "_kcfstreamerrordomainkey" = 4; } 

i have no idea going wrong here! appreciated. while device connected xcode, got url out , uploaded file via curl. fwiw, works too!

after 2 days, found problem! part of code did not post, how initializing aws client.

    awsstaticcredentialsprovider *cp = [[awsstaticcredentialsprovider alloc] initwithaccesskey:accesskey secretkey:secretkey];     awsserviceconfiguration* config = [[awsserviceconfiguration alloc] initwithregion:awsregionuseast1 credentialsprovider:cp];     awsservicemanager.defaultservicemanager.defaultserviceconfiguration = config; 

now, there library using did same thing, different credentials different bucket. since other library getting called after code, having problems uploading file. why error request timed out instead of invalid credentials, haven't found out yet.

i changed initialization code --

    awsstaticcredentialsprovider *cp = [[awsstaticcredentialsprovider alloc] initwithaccesskey:accesskey secretkey:secretkey];     awsserviceconfiguration* config = [[awsserviceconfiguration alloc] initwithregion:awsregionuseast1 credentialsprovider:cp];     [awss3transfermanager registers3transfermanagerwithconfiguration:config forkey:awslogfilesuploaderkey]; 

and obtained instance of awss3transfermanager --

awss3transfermanager* tm = [awss3transfermanager s3transfermanagerforkey:awslogfilesuploaderkey]; 

and went smooth!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -