How do I download a file from S3 to an iPhone application?

后端 未结 2 1680
失恋的感觉
失恋的感觉 2021-02-06 17:11

I am new to iPhone development. I am developing an iPhone application which needs to open files stored on Amazon\'s S3 service.

How do I download a file from S3 to my

2条回答
  •  不知归路
    2021-02-06 17:25

    I always use the ASIHttpRequest library to do this and it's quite simple, here's a sample code from their website:

    NSString *secretAccessKey = @"my-secret-access-key";
    NSString *accessKey = @"my-access-key";
    NSString *bucket = @"my-bucket";
    NSString *path = @"path/to/the/object";
    
    ASIS3ObjectRequest *request = [ASIS3ObjectRequest requestWithBucket:bucket key:path];
    [request setSecretAccessKey:secretAccessKey];
    [request setAccessKey:accessKey];
    [request startSynchronous];
    if (![request error]) {
      NSData *data = [request responseData];
    } else {
      NSLog(@"%@",[[request error] localizedDescription]);
    }
    

    You can't get easier than this :)

提交回复
热议问题