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.
S3ListObjectsRequest *lor = [S3ListObjectsRequest alloc];
lor.bucket = @"bucketName";
lor.prefix = @"/folderName1/foldername2";
S3ListObjectsResponse *ListObjectResponse = [self.s3 listObjects:lor];
Just simply DO NOT put "/" in front of folderName1, and things will work out.
Swift:
let listObjectsRequest = AWSS3ListObjectsRequest()
listObjectsRequest.bucket = "(your bucket name)"
listObjectsRequest.prefix = "(subfolder1)/(subfolder2)"
s3.listObjects(listObjectsRequest).continueWithBlock { (task) -> AnyObject! in .......
Objective-C:
S3ListObjectsRequest *lor = [S3ListObjectsRequest alloc];
lor.bucket = @"bucketName";
lor.prefix = @"folderName1/foldername2";
S3ListObjectsResponse *ListObjectResponse = [self.s3 listObjects:lor];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With