iPhone API for Accessing Amazon S3 REST API

久未见 提交于 2020-01-01 00:54:06

问题


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.


回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/1004271/iphone-api-for-accessing-amazon-s3-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!