AWS下载文件到iOS

时间:2013-07-09 18:42:48

标签: objective-c xcode amazon-web-services amazon-s3 cloud

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);     NSString * documentPath = [paths objectAtIndex:0];

NSString *temp = [NSString stringWithFormat:@"%@/temp.txt", documentPath];
NSLog(temp);




// create our stream
NSOutputStream *outputStream =
[[NSOutputStream alloc] initToFileAtPath:temp append:YES];
[outputStream open];

// create our request
S3GetObjectRequest *getObjectRequest =
[[S3GetObjectRequest alloc] initWithKey:self.objectName
withBucket:self.bucket];
getObjectRequest.outputStream = outputStream;




// always make sure to close your streams when done
[outputStream close];

1 个答案:

答案 0 :(得分:2)

您需要使用NSSearchPathForDirectoriesInDomains获取应用程序的文档目录,并使用它来构建文件路径和名称。

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentPath = [paths objectAtIndex:0];