How to return a list of objects in Amazon S3 using PHP in a particular order

Go To StackoverFlow.com

1

I am using the Amazon S3 SDK for PHP. I am wondering if there is a way to retrieve the objects in a particular order, like by file name, or by modified date. Currently it is just listing them based on when they were uploaded. I am using this method, but maybe there is another method that would fit better.

$object_list_array = $s3->get_object_list(MYBUCKET, array(
  'prefix' => '/path/to/folder/with/files/'
));

What is the best way to express what order I would like them returned?

2012-04-05 22:09
by Jason


0

I don't think it's possible. If you check the definition of the get_object_list function in

sdk/services/s3.class.php

it lists a load of options which can be passed, but there's a notable lack of an option to define the order of the results:

  • delimiter
  • marker
  • max-keys
  • pcre
  • prefix
  • curlopts

In my limited testing it seems to return the files ordered by their name rather than their creation date.

2012-05-03 15:20
by user1207727


0

Not using the SDK directly. However, there are alternative options. For example, if you were to store your objects in an array, you can take advantage of PHP's numerous array-sorting methods.

See here: http://php.net/manual/en/array.sorting.php

2012-07-23 17:05
by Nathanael
Ads