Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List objects in a specific folder on Amazon S3

Tags:

php

sdk

amazon-s3

I am trying to get the list of Object under a specific folder in my bucket.

I know that to get a list of all of my objects I do:

    $objects = $client->getIterator('ListObjects', array(     'Bucket' => $bucket ));  

I want to get only the objects under the folder my/folder/test. I have tried adding

        'key' => "my/folder/test", 

And

        'prefix' => "my/folder/test", 

But it simply returns all of the objects in my bucket.

like image 714
Dvir Levy Avatar asked Sep 08 '13 11:09

Dvir Levy


1 Answers

You need to use Prefix to restrict the search to a specific directory (a common prefix).

$objects = $client->getIterator('ListObjects', array(     "Bucket" => $bucket,     "Prefix" => "your-folder/" ));  
like image 66
dcro Avatar answered Sep 21 '22 21:09

dcro