2

Ok, I see this and this and documentation telling amazon is flat file system and for to create/get/set folders , one has to use Delimiter='/' and Prefix.

But I didnt get it, I mean I couldnt write the code. So I have a bucket and a folder with some files,I want list of those files

So I tried bucket/folder , /bucket/folder/ , bucket/folder/ all of this fails.

If I try only bucket, it works fine

S3ListObjectsRequest *getListObjectsRequest= [[S3ListObjectsRequest alloc] initWithName:@"bucket"]; // tried also here bucket/folder , /bucket/folder/ ,  bucket/folder/ 
    S3ListObjectsResponse *getListObjectsResponse = [self.s3 listObjects:getListObjectsRequest];

    //test to see inside of the folder
    NSArray *objectsinamazon = [self.s3 listObjectsInBucket:@"bucket"]; //as I said I tried bucket/folder , /bucket/folder/ ,  bucket/folder/ all od this fails.

    NSLog(@"array is %@",objectsinamazon);

    S3ListObjectsResult *listObjectsResults = getListObjectsResponse.listObjectsResult;



    for (S3ObjectSummary *objectSummary in listObjectsResults.objectSummaries) {

        NSLog(@"Bucket Contents %@:",[objectSummary key]);
       //get last modified date of file by using meta data
    S3GetObjectMetadataRequest *getMetadataRequest = [[S3GetObjectMetadataRequest alloc] initWithKey:[objectSummary key] withBucket:@"bucket"];
    S3GetObjectMetadataResponse *getMetadataResponse = [self.s3 getObjectMetadata:getMetadataRequest];

}
}

I am asking exact syntax(code) to send bucket/folder request to amazon s3

Community
  • 1
  • 1
Mord Fustang
  • 1,523
  • 4
  • 40
  • 71
  • Hi @MordFustang here is [my answer](http://stackoverflow.com/questions/38454387/how-to-list-the-folders-at-a-specific-path-from-an-amazon-s3-bucket-in-objectiv/38454388#38454388) to this question, hope it helps. – Laur Stefan Jul 19 '16 at 09:22

1 Answers1

4

S3 is not flat, it just has only two levels: the bucket and the object name (it is flat inside the bucket). The bucket is always just the bucket. You're trying to add on to your bucket name, which produces an invalid bucket name.

The prefix and delimiter parameters are properties on S3ListObjectsRequest. My Objective-C is rusty, but I think you can set those properties with:

getListObjectsRequest.prefix = @"my/prefix/";
getListObjectsRequest.delimiter = @"/";

before you submit the request to S3.

rhashimoto
  • 15,650
  • 2
  • 52
  • 80