AWS S3 File Download with Objective-C Successful Then Unsuccessful - ios

I have a strange problem using AWS S3. The first time I call the code, files are downloaded from the S3 service as expected. The next time I call the code to download additional files, it hangs.
I am using version 2.1.2 of the AWS iOS SDK. I have downloaded and installed the SDK using cocoapods. I have read other threads on Stack Overflow and they do not address this issue.
The code:
static AWSStaticCredentialsProvider *credentialsProvider;
static AWSServiceConfiguration *configuration;
static AWSS3 *transferManager;
//This code is run when the object is instantiated
-(id)init
{
if ( self = [super init] ) {
credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:#“ACCESS KEY" secretKey:#“SECRET"];
configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
transferManager = [[AWSS3 alloc] initWithConfiguration:configuration];
}
return self;
}
-(UIImage *) getImageData:(NSString *)imageName
{
AWSS3 *transferManager = [[AWSS3 alloc] initWithConfiguration:configuration];
AWSS3GetObjectRequest *getImageRequest = [AWSS3GetObjectRequest new];
getImageRequest.bucket = #"quizontapimages/quizimages";
getImageRequest.key = imageName;
getImageRequest.key = [getImageRequest.key stringByAppendingString:#".png"];
BFTask *downloadTask1 = [[transferManager getObject:getImageRequest] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
if(task.error)
{
NSLog(#"Error: %#",task.error);
}
else
{
NSData *data = [task.result body];
image = [UIImage imageWithData:data];
}
return nil;
}];
[downloadTask1 waitUntilFinished];
return image;
}
I have also tried commenting out the first line of getImageData method to use the initialized transferManager with the same results.
When I use AWS verbose logging on the successful download I get the following information:
2015-06-11 16:12:51.199 QuizOnTap[7362:538728] AWSiOSSDKv2 [Debug] AWSSignature.m line:241 | -[AWSSignatureV4Signer signS3RequestV4:] | Canonical request: [GET
/quizontapimages/quizimages/WABD_QSI_333x118.png
content-type:binary/octet-stream
host:s3.amazonaws.com
user-agent:aws-sdk-iOS/2.0.17 iPhone-OS/8.3 en_US
x-amz-content-sha256:*some key*
x-amz-date:20150611T211251Z
content-type;host;user-agent;x-amz-content-sha256;x-amz-date
*some key*]
2015-06-11 16:12:51.199 QuizOnTap[7362:538728] AWSiOSSDKv2 [Debug] AWSSignature.m line:248 | -[AWSSignatureV4Signer signS3RequestV4:] | AWS4 String to Sign: [AWS4-HMAC-SHA256
20150611T211251Z
20150611/us-east-1/s3/aws4_request
*some key*]
2015-06-11 16:12:51.493 QuizOnTap[7362:539182] AWSiOSSDKv2 [Debug] AWSURLResponseSerialization.m line:258 | -[AWSXMLResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response header: [{
"Accept-Ranges" = bytes;
"Content-Length" = 15947;
"Content-Type" = "image/png";
Date = "Thu, 11 Jun 2015 21:12:52 GMT";
Etag = "\"ff690cf7807b538278fc1590ce446785\"";
"Last-Modified" = "Sun, 31 May 2015 16:14:42 GMT";
Server = AmazonS3;
"x-amz-id-2" = "QIu6OWhmuO53z6Qgo+Q/4gsN4dQbyCAPbwS4QyDm/pmmSRXj8M5O4x5GoXMQq/rgSh0AKqt0uVk=";
"x-amz-request-id" = E0DB22A10F901130;
}]
2015-06-11 16:12:51.493 QuizOnTap[7362:539182] AWSiOSSDKv2 [Verbose] AWSURLResponseSerialization.m line:263 | -[AWSXMLResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body: [(null)]
Later on in the process I call the same identical code that never returns from [downloadTask1 waitUntilFinished];. Below is the AWS verbose log for that transaction. Notice the long running operation warning as well.
2015-06-11 16:14:03.075 QuizOnTap[7362:538689] AWSiOSSDKv2 [Debug] AWSSignature.m line:241 | -[AWSSignatureV4Signer signS3RequestV4:] | Canonical request: [GET
/quizontapimages/quizimages/neat_square_1.png
content-type:binary/octet-stream
host:s3.amazonaws.com
user-agent:aws-sdk-iOS/2.0.17 iPhone-OS/8.3 en_US
x-amz-content-sha256:*some key*
x-amz-date:20150611T211403Z
content-type;host;user-agent;x-amz-content-sha256;x-amz-date
*some key*]
2015-06-11 16:14:03.075 QuizOnTap[7362:538689] AWSiOSSDKv2 [Debug] AWSSignature.m line:248 | -[AWSSignatureV4Signer signS3RequestV4:] | AWS4 String to Sign: [AWS4-HMAC-SHA256
20150611T211403Z
20150611/us-east-1/s3/aws4_request
*some key*]
2015-06-11 16:14:03.076 QuizOnTap[7362:538689] Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
2015-06-11 16:14:03.396 QuizOnTap[7362:540085] AWSiOSSDKv2 [Debug] AWSURLResponseSerialization.m line:258 | -[AWSXMLResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response header: [{
"Accept-Ranges" = bytes;
"Content-Length" = 4998;
"Content-Type" = "image/png";
Date = "Thu, 11 Jun 2015 21:14:04 GMT";
Etag = "\"7b27202a6560ed99277acebf2235ba89\"";
"Last-Modified" = "Fri, 22 May 2015 15:16:13 GMT";
Server = AmazonS3;
"x-amz-id-2" = "5TxaPQy8jblFr8qVXfiSg3pK0EfOqSdEWdykE0kfRKUdrfxvmxvYvzf0uXGYiXXliAG/DbM55tM=";
"x-amz-request-id" = 9F7BC6AC5494D285;
}]
2015-06-11 16:14:03.396 QuizOnTap[7362:540085] AWSiOSSDKv2 [Verbose] AWSURLResponseSerialization.m line:263 | -[AWSXMLResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body: [(null)]

You are not retaining a strong reference to the transferManager object in - getImageData:. Please remember that - getObject: is an asynchronous method, and it returns immediately. You need to retain a strong reference to the service client until the request finishes processing.
If you use the AWS Mobile SDK for iOS 2.1.2, Xcode should give you a compiler warning for the use of - initWithConfiguration:. The method was deprecated to mitigate the misuse of the API such as this case. Please use + defaultS3TransferManager or + S3TransferManagerForKey: to retrieve the AWSS3TransferManager object.
(Also, the log indicates you are using 2.0.17 instead of 2.1.2.)

Related

End point does not exists - AWS SNS

I'm getting "Endpoint does not exists" when I'm trying to register for topic from my ios project. Inside info.plist file, I set my SNSPlatformApplicationARN to the app I created in SNS console. I've been scratching my heads of to resolve this issue. I appreciate any help. This is full error :
016-12-11 12:52:05.534 MiGPShttps://forums.aws.amazon.com/ AWSiOSSDK v2.4.11 https://forums.aws.amazon.com/ AWSURLSessionManager.m line:212 | -https://forums.aws.amazon.com/ | Session task failed with error: Error Domain=NSPOSIXErrorDomain Code=54 "Connection reset by peer" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=54}
2016-12-11 12:52:05.820 MiGPShttps://forums.aws.amazon.com/ AWSiOSSDK v2.4.11 https://forums.aws.amazon.com/ AWSURLSessionManager.m line:553 | -https://forums.aws.amazon.com/ | Response headers:
{
"Content-Length" = 262;
"Content-Type" = "text/xml";
Date = "Sun, 11 Dec 2016 17:52:05 GMT";
"x-amzn-RequestId" = "xxxx";
}
2016-12-11 12:52:05.820 MiGPShttps://forums.aws.amazon.com/ AWSiOSSDK v2.4.11 https://forums.aws.amazon.com/ AWSURLResponseSerialization.m line:240 | -https://forums.aws.amazon.com/ | Response body:
<ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
<Error>
<Type>Sender</Type>
<Code>NotFound</Code>
<Message>Endpoint does not exist</Message>
</Error>
<RequestId>xxxx-xxx-xxx</RequestId>
</ErrorResponse>

AFNetworking POST get 403 forbidden, but Curl works

I want to use AFNetworking to POST to sinatra project to get json data. AFNetwroking always get back 403 status code. But curl works as expect. Why?
Here is the error on Xcode:
<AFHTTPRequestOperation: 0x7ffd5da42780, state: isFinished, cancelled: NO request: <NSMutableURLRequest: 0x7ffd5d9591b0> { URL: http://127.0.0.1:9292/api/v1/events/new }, response: <NSHTTPURLResponse: 0x7ffd5b7b7030> { URL: http://127.0.0.1:9292/api/v1/events/new } { status code: 403, headers {
Connection = "Keep-Alive";
"Content-Length" = 69;
"Content-Type" = "application/json";
Date = "Fri, 23 Jan 2015 08:42:32 GMT";
Server = "WEBrick/1.3.1 (Ruby/2.1.5/2014-11-13)";
"X-Content-Type-Options" = nosniff;
} }>
Curl on terminal:
curl http://127.0.0.1:9292/api/v1/events/new
{"error_code":10001,"error_message":"need token or token is illegal"}%
IOS code doesn't work:
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:
[NSURL URLWithString:#"http://127.0.0.1:9292/"]];
[manager POST:#"api/v1/events/new"
parameters:nil
success:nil
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{DLog(#"%#",operation);}];
rackup log:
[2015-01-23 16:58:20] INFO WEBrick 1.3.1
[2015-01-23 16:58:20] INFO ruby 2.1.5 (2014-11-13) [x86_64-darwin14.0]
[2015-01-23 16:58:20] INFO WEBrick::HTTPServer#start: pid=14445 port=9292
127.0.0.1 - - [23/Jan/2015:16:58:36 +0800] "POST /api/v1/events/new HTTP/1.1" 403 69 0.0179
Actually it works right, my server side make a path filter, but here provide a way, sometime not only just print operation but also operation.responseObject which i got what i want.
{
"error_code" = 10001;
"error_message" = "need token or token is illegal";
}

Getting Request failed: unacceptable (406) when posting parameters

i am posting the parameter in the web-service. using the below code. and i am getting the "Request failed: unacceptable (406) Error .I am not sure is im posting it right .
I tried posting the data using their key and value pair using POSTMAN chrome app . and it is working fine there.Not here pls suggest .i am using Afnetworking for the first time
[params setValue:self.txtUserName forKey:#"name"];
[params setValue:self.txtEmail forKey:#"mail"];
[params setValue:self.txtPass forKey:#"conf_mail"];
[params setValue:self.txtPass2 forKey:#"pass"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:#"http://charlie.indivar.info/ministore/store-commerce/user/register"
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"JSON: %#", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error Retrieving Data"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}];
Below is the console log
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unacceptable (406)" UserInfo=0x8deb400 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x8ddddf0> { URL: http://website.com/ministore/store-commerce/user/register } { status code: 406, headers {
"Cache-Control" = "no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = "Keep-Alive";
"Content-Length" = 396;
"Content-Type" = "application/json";
Date = "Fri, 10 Oct 2014 07:06:40 GMT";
Etag = "\"1412924800\"";
Expires = "Sun, 19 Nov 1978 05:00:00 GMT";
"Keep-Alive" = "timeout=5, max=100";
"Last-Modified" = "Fri, 10 Oct 2014 07:06:40 +0000";
Server = Apache;
"Set-Cookie" = "SESSd5cd87b70f9ea9019d306d6f4e440b74=5lpY8-PvQYRM5IBWiGk33EeXsucAJCBZQSce7vRBhEY; expires=Sun, 02-Nov-2014 10:40:01 GMT; path=/; domain=website.com; HttpOnly";
Vary = Accept;
"X-Drupal-Cache" = MISS;
"X-Powered-By" = "PHP/5.3.10-1ubuntu3.14";
} }, NSErrorFailingURLKey=http://website.com/ministore/store-commerce/user/register, NSLocalizedDescription=Request failed: unacceptable (406), com.alamofire.serialization.response.error.data=
0a7b2273 74617475 73223a22 30222c22 64617461 223a7b22 6e616d65 223a2255 7365726e 616d6520 63616e6e
6f742062 65206c6f 6e676572 20746861 6e203630 20636861 72616374
65727320 62757420 69732063 75727265 6e746c79 20323031 20636861
72616374 65727320 6c6f6e67 2e222c22 6d61696c 223a2254 68652065
2d6d6169 6c206164 64726573 7320266c 743b5549 54657874 4669656c
643a2030 78386462 63306230 3b206672 616d6520 3d202835 37203135
343b2031 35332033 30293b20 74657874 203d2026 23303339 3b646565
70616b73 6f6f6440 64656570 616b2e63 6f6d2623 3033393b 3b20636c
69707354 6f426f75 6e647320 3d205945 533b206f 70617175 65203d20
4e4f3b20 6175746f 72657369 7a65203d 20524d2b 424d3b20 67657374
75726552 65636f67 6e697a65 7273203d 20266c74 3b4e5341 72726179
3a203078 38663665 38613026 67743b3b 206c6179 6572203d 20266c74
3b43414c 61796572 3a203078 38646165 65653026 67743b26 67743b20
6973206e 6f742076 616c6964 2e227d7d>}
If the Web server detects that the data it wants to return is not
acceptable to the client, it returns a header containing the 406 error
code. This error occurs very infrequently in Web browsers, because most browsers will accept any data returned from the Web server.
Looks like the server is not recognized that you are mobile etc...
http://www.checkupdown.com/status/E406.html
This is a very old question, BUT:
You need to read the response data send by the server, the "0a7b2273..." part.
There, if you do:
NSString *responseString = [[NSString alloc] initWithData:thatData encoding:NSUTF8StringEncoding];
You'll see that the value is (it's JSON, I just linted it):
{
"status": "0",
"data": {
"name": "Username cannot be longer than 60 characters but is currently 201 characters long.",
"mail": "The e-mail address <UITextField: 0x8dbc0b0; frame = (57 154; 153 30); text = 'deepaksood#deepak.com'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x8f6e8a0>; layer = <CALayer: 0x8daeee0>> is not valid."
}
}
Your error was that in:
[params setValue:self.txtUserName forKey:#"name"];
self.txtEmail is a UITextField, not the textField.text. So, it was either self.txtEmail.text, or at some point, you wrote self.txtEmail = textField instead of self.txtEmail = textField.text. I guess this was also the case for the userName.
• So, after so much time, what's the thing that can still be applied nowadays:
Read the returned value! If might contain useful information on why it failed. When debugging, grab as much info as possible: HTTP Code, values send/read/received, etc.

ios wsdl2objc response error 500

i am trying to make a request to a SOAP web service with the code below.
BasicHttpBinding_IGTBEihaleWSBinding *binding = [GTBEIhaleWSSvc BasicHttpBinding_IGTBEihaleWSBinding];
binding.logXMLInOut = YES;
GTBEIhaleWSSvc_IhaleListesiGetir *request = [GTBEIhaleWSSvc_IhaleListesiGetir new];
BasicHttpBinding_IGTBEihaleWSBindingResponse *response = [binding IhaleListesiGetirUsingParameters:request];
NSArray *responseHeaders = response.headers;
NSArray *responseBodyParts = response.bodyParts;
However, i am getting this error.
2014-02-21 11:33:36.348 Mobil Ihale Uygulamasi[22801:70b] ResponseStatus: 500
2014-02-21 11:33:36.349 Mobil Ihale Uygulamasi[22801:70b] ResponseHeaders:
{
Connection = close;
"Content-Length" = 449;
"Content-Type" = "text/xml;charset=UTF-8";
Date = "Fri, 21 Feb 2014 09:33:21 GMT";
Server = "Apache-Coyote/1.1";
}
2014-02-21 11:33:36.350 Mobil Ihale Uygulamasi[22801:70b] ResponseError:
Error Domain=BasicHttpBinding_IGTBEihaleWSBindingResponseHTTP Code=500 "internal server error" UserInfo=0x10923ce40 {NSLocalizedDescription=internal server error}
I don't have a problem with another SOAP service with this approach.
The cause of the problem is about wsdl2objc's parsing. Something is wrong with the generated code. Thus, I found another tool named Easy WSDL. It just worked perfect for me.

iOS, RESTKit and oAuth - simple sample not working

I am writing a simple application on iOS and I am trying to consume a RESTFull webservice
To have some tips and get some knowledge I first start with twitter without using ios integrated libs, but I always get stocked on Auth.
Any working sample or link will be appreciated, as reminder twitter is not my final goal
For instance this is one of my code, based on RestKit and AFOAuth1Client :
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com"];
AFOAuth1Client * twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:url key:kCLIENTID secret:kCLIENTSECRET];
[twitterClient authorizeUsingOAuthWithRequestTokenPath:#"oauth/request_token"
userAuthorizationPath:#"oauth/authorize"
callbackURL:[NSURL URLWithString:#"af-twitter://success"]
accessTokenPath:#"oauth/access_token"
accessMethod:#"POST"
scope:#""
success:^(AFOAuth1Token *token, id responseObject) {
}
failure:^(NSError *error) {
}];
as you can see it does not work :
2013-06-17 16:59:01.389 restKitTest[14490:c07] I restkit:RKLog.m:34 RestKit logging initialized...
2013-06-17 16:59:02.653 restKitTest[14490:c07] I restkit.network:RKObjectRequestOperation.m:174 POST 'http://api.twitter.com/oauth/request_token'
2013-06-17 16:59:03.051 restKitTest[14490:c07] E restkit.network:RKObjectRequestOperation.m:203 POST 'http://api.twitter.com/oauth/request_token' (401 Unauthorized) [0.3980 s]: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x9c96640 {NSLocalizedRecoverySuggestion=Failed to validate oauth signature and token, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x9877e20> { URL: http://api.twitter.com/oauth/request_token }, NSErrorFailingURLKey=http://api.twitter.com/oauth/request_token, NSLocalizedDescription=Expected status code in (200-299), got 401, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x9aac910> { URL: http://api.twitter.com/oauth/request_token } { status code: 401, headers {
"Cache-Control" = "no-cache, no-store, must-revalidate, pre-check=0, post-check=0";
"Content-Encoding" = gzip;
"Content-Length" = 62;
"Content-Type" = "text/html; charset=utf-8";
Date = "Mon, 17 Jun 2013 14:59:03 GMT";
Expires = "Tue, 31 Mar 1981 05:00:00 GMT";
"Last-Modified" = "Mon, 17 Jun 2013 14:59:03 GMT";
Pragma = "no-cache";
Server = tfe;
"Set-Cookie" = "_twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCOJ3pVI%252FAToHaWQiJTIyYzUxN2UwNmUwYTI4%250AYzU1NmU0OTYxZDA5MDcwMmI3IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--3291687666d367b6ccddc74513532bf56ea144d9; domain=.twitter.com; path=/; HttpOnly, guest_id=v1%3A137148114312677519; Domain=.twitter.com; Path=/; Expires=Wed, 17-Jun-2015 14:59:03 UTC";
Status = "401 Unauthorized";
Vary = "Accept-Encoding";
"x-frame-options" = SAMEORIGIN;
"x-mid" = af106773611449e1226d5dd5d531b64d91e4f3f8;
"x-runtime" = "0.01153";
"x-transaction" = 24e58d8eb3b7cdb5;
"x-ua-compatible" = "IE=10,chrome=1";
"x-xss-protection" = "1; mode=block";
} }}
"401 Unauthorized" indicates that your credentials are incorrect. So check your API keys.
try this:
[twitterClient authorizeUsingOAuthWithRequestTokenPath:#"/oauth/request_token"
userAuthorizationPath:#"/oauth/authorize"
callbackURL:[NSURL URLWithString:#"instantshare-twitter://success"]
accessTokenPath:#"/oauth/access_token"
accessMethod:#"POST"
scope:nil
success:^(AFOAuth1Token *accessToken, id responseObject) {
[twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
} failure:^(NSError *error) {
NSLog(#"Error: %#", error);
}];
Note the line scope:nil, for some reason it doesn't work with empty string.
Among other things, check your application settings in twitter. I'm not sure if this is the case, but I enabled Allow this application to be used to Sign in with Twitter and set Callback URL to some random valid url

Resources