亚马逊AWS IOS SDK:如何列出所有文件名的文件夹 [英] Amazon AWS IOS SDK: How to list ALL file names in a FOLDER

查看:687
本文介绍了亚马逊AWS IOS SDK:如何列出所有文件名的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AWS的IOS SDK和尝试列出文件夹中的所有文件。

I'm using AWS IOS SDK and trying to list all the files in a FOLDER.

这code工作要列出一个桶中的所有文件等:

This code works to list all files etc in a BUCKET:

-(void) s3DirectoryListing: (NSString *) bucketName {

    s3Client = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY withSecretKey:SECRET_KEY];

    @try {

        S3ListObjectsRequest *req = [[S3ListObjectsRequest alloc] initWithName:bucketName];

        S3ListObjectsResponse *resp = [s3Client listObjects:req];

        NSMutableArray* objectSummaries = resp.listObjectsResult.objectSummaries;  

        for (int x = 0; x < [objectSummaries count]; x++) {
            NSLog(@"objectSummaries: %@",[objectSummaries objectAtIndex:x]);
        }
    }
    @catch (NSException *exception) {
    NSLog(@"Cannot list S3 %@",exception);
}

}

所以,如果我通过一个bucketName的名字,这个工程。但是,如果我试图通过bucketName /夹folderName我得到一个错误信息。这code似乎并不像桶和文件夹路径组合的组合。

So if I pass a bucketName name, this works. However if I try and pass bucketName/folderName" I get an error message. This code doesn't seem to like the combination of bucket and folder path combinations.

任何想法AP preciated。

Any ideas appreciated.

推荐答案

亚马逊S3是一个平的文件系统,这意味着它没有物理文件夹。 文件夹正如你所知道的只是prefixes添加到文件名。

Amazon S3 is a "flat" file system, meaning it does not have physical folders. "Folders" as you know are simply prefixes added to file names.

您需要将 preFIX 属性设置为你的要求(见<一href="http://docs.amazonwebservices.com/AWSiOSSDK/latest/class_s3_list_objects_request.html">documentation)

You need to set the prefix property to your request (see the documentation)

例如,考虑以下文件集:

For example, given the following set of files:

folderName1 / fileNameA.txt
  folderName1 / fileNameB.txt
  folderName2 / folderName3 / fileNameC.txt

folderName1/fileNameA.txt
folderName1/fileNameB.txt
folderName2/folderName3/fileNameC.txt

如果您设置 preFIX folderName1 ,和你的分隔符 / ,你应该得到的只有前两个条目。

If you set prefix with folderName1, and your delimiter with /, you should get only the first two entries.

最后,但并非最不重要的,离开你的 bucketName 只能用水桶名称:)

Last, but not least, leave your bucketName only with the bucket name :)

S3开发者指南更多信息。

这篇关于亚马逊AWS IOS SDK:如何列出所有文件名的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆