Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 list object in reverse order

Currently when i call $s3->list_objects() method it return me objects in the order those objects were added. I want to list object in reverse order so that i can have newest objects first. I cannot find any parameter that i can pass to the $s3->list_objects() method that can reverse the order. I am using Amazon S3 PHP SDK. Is there is any such parameter or method?

like image 660
Khawer Zeshan Avatar asked Jan 18 '13 08:01

Khawer Zeshan


People also ask

What does S3 Listobjects return?

Returns some or all (up to 1,000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK response can contain valid or invalid XML.

What does Getobject return?

Retrieves objects from Amazon S3. To use GET , you must have READ access to the object. If you grant READ access to the anonymous user, you can return the object without using an authorization header.

What is an S3 marker?

A delete marker in Amazon S3 is a placeholder (or marker) for a versioned object that was named in a simple DELETE request. Because the object is in a versioning-enabled bucket, the object is not deleted.


1 Answers

I'm looking to do the same thing and I really don't feel like I want a DB in the way to keep track of the latest objects. Since you just need them to have alphabetically reverse order keys.

A timestamp is alphabetical in ordering usually. A timestamp can be represented as a long. We can get a reverse alphabetical time identifier by taking the (max long - timestamp long) and formatting that with all leading 0s.

So if you store your S3 Objects with the key = prefix + timestampId + postfix you can use list to get the newest objects.

like image 171
myyk Avatar answered Oct 20 '22 21:10

myyk