0

Does anyone have any suggestions for GETing from or POSTing to Amazon S3 services using their REST API via the iPhone. It does not look like it is possible but I may be reading the docs wrong.

Thank you in advance for your help!

L.

5
  • Why does it not look possible? It is just a REST API after all. Commented Jun 16, 2009 at 22:56
  • To the best of my knowledge the only Cocoa/Cocoa Touch based toolkit for accessing S3 is ConnectionKit. Otherwise you are stuck with building your own, which could become quite a complex task. May I ask which bits of the API you require? The current release of ConnectionKit does support S3 but is a bit ropey. We're currently in the process of writing the 2.0 version. If we have someone to work with specifically for one protocol, we could focus purely on that for now to our mutual benefit. Please contact me at mikeabdullah.net/other/contact_me.html for further discussion if interested Commented Jun 17, 2009 at 23:41
  • The reason why it appears not possible is that each authenticated request to S3 servers needs to have a RFC 2104HMAC-SHA1 signature generated and sent along with the request. To my knowledge, there is currently no way to do this on the iPhone. Am I incorrect or just missing something? Commented Jun 18, 2009 at 15:22
  • 1
    On the iPhone there is CCHMAC(3) which offers the required functionality Commented Jun 18, 2009 at 18:22
  • Thanks Mike. No sooner did I write my last comment I came across that exact library. I hadn't realized it was in there. That's exactly what I am going with. Thank you again! Commented Jun 19, 2009 at 14:24

2 Answers 2

3

In a general case I'd recommend to use ASIHttpRequest, it has a lot of built-in functionality (REST compatible too) and a lot of things, making life easier than with NSURLConnection.

It also has S3 support out of box.

Sign up to request clarification or add additional context in comments.

2 Comments

I think you're a little confused. NSConnection is for Distributed Objects. Very different to NSURLConnection!
Yes, you're right, I meant NSURLConnection. Will update answer.
2

You should be able to use the NSURLRequest stuff to do what you want.

NSMutableData* _data = nil;

- (IBAction) doIt:(id)sender {
    NSURL* url = [NSURL URLWithString: @"http://theurl.com/"];
    NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL: url];
    NSURLConnection* con = [NSURLConnection connectionWithRequest: req delegate: self];
    NSData* body = [@"body of request" dataUsingEncoding: NSUTF8StringEncoding];

    _data = [NSMutableData new];
    [req setHTTPMethod: @"POST"];
    [req setHTTPBody: body];
    [con start];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [_data appendData: data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString* result = [[[NSString alloc] initWithData: _data encoding: NSUTF8StringEncoding] autorelease];

    // process your result here
    NSLog(@"got result: %@", result);
}

This doesn't have any error checking in it and the _data variable should be stored in an instance variable, but the general idea should work for you. You will probably also need to set some request headers to tell the server what encoding the body data is in and so on.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.