Question:
I am using the AWS IOS SDK to download files from S3 and am having trouble listing objects in a specific folder of an S3 bucket. I can list all the files of the ENTIRE bucket using the listObjectsInBucket method but I need to list only the files in a specific folder within a bucket.
So I am trying to use the listObjects method and specify a bucket name and prefix (indicating a folder name on S3).
But the following code is not working.
1 2 3 4 5 6 |
S3ListObjectsRequest *lor = [S3ListObjectsRequest alloc]; lor.bucket = @"bucketName"; lor.prefix = @"/folderName1/foldername2"; S3ListObjectsResponse *ListObjectResponse = [self.s3 listObjects:lor]; |
Answer:
Just simply DO NOT put “/” in front of folderName1, and things will work out.
Swift:
1 2 3 4 5 |
let listObjectsRequest = AWSS3ListObjectsRequest() listObjectsRequest.bucket = "(your bucket name)" listObjectsRequest.prefix = "(subfolder1)/(subfolder2)" s3.listObjects(listObjectsRequest).continueWithBlock { (task) -> AnyObject! in ....... |
Objective-C:
1 2 3 4 5 6 |
S3ListObjectsRequest *lor = [S3ListObjectsRequest alloc]; lor.bucket = @"bucketName"; lor.prefix = @"folderName1/foldername2"; S3ListObjectsResponse *ListObjectResponse = [self.s3 listObjects:lor]; |