Given my S3 bucket, which contains images in such a structure:
root/portraits/portrait_001.jpg root/landscapes/landscape_001.jpg
where root is my bucket, and there are no other files in my root, only those folders (objects), how can I get a list of only these objects?
portraits/ landscapes/
I am familiar with using separator and prefix in ListObjects call.
If I do the following, I get no results:
$objects = $s3->getIterator('ListObjects', array( 'Bucket' => $bucket, 'Delimiter' => '/', )); foreach($objects as $object) echo $object['Key'] . "\n";
If I do not use the delimiter, I get everything, obviously.
I cannot use the prefix because the objects that I need are root. Otherwise, I have no problem using the prefix to say list only the files in 'portraits /'
From my searches, I managed to find solutions of previous years that apply only to aws php sdk v1 or v2, and I had no luck in this (v3 is completely different)
Any suggestions? I feel that I am missing something simple, but looking through the documentation, I can not find anything to help me. As a last resort, I just need to manually declare an array
$categories = ['portraits/', 'landscapes/']
But this is not ideal when I want to add more categories in the future, and I donβt have to worry about adding another category manually.
Any help would be greatly appreciated :)
Change - Solution
I must have looked for the wrong places during my dumps of objects, but in the end I saw common prefixes in the returned result of calling ListObjects with a delimiter '/', for example:
$s3->listObjects(array('Bucket' => $bucket, 'Delimiter' => '/'));