0

I have been trying to figure out how to get files that are at the Root level, meaning get all files that don't have a path attached to their file name. I have a container that looks like this

image.png            image/png
ui                   application/directory
ui/css               application/directory
ui/css/test.css      text/css
ui/image2.jpg        image/jpg

I'm using the call

Container->get_objects(0, null, null, 'ui/');

which returns 2 CF_Objects:

ui/css
ui/image2.jpg

This is the desired output

but if I request the files at the "root level"

Container->get_objects(0, null, null, '/');

returns an empty array.

Container->get_objects(0, null, null, '');

returns all the files in the container.

Ideally It would return two CF_Objects image.png, and ui.

Is there a way to do this?

Thank you!

2 Answers 2

1

The Cloud Files Developer guide of Nov 15 2011 page 20 says:

You can also use a delimiter parameter to represent a nested directory hierarchy without the need for the directory marker objects. You can use any single character as a delimiter. The listings can return virtual directories - they are virtual in that they don't actually represent real objects. like the directory markers, though, they will have a content-type of application/directory and be in a subdir section of json and xml results.

If you have the following objects—photos/photo1, photos/photo2, movieobject, videos/ movieobj4—in a container, your delimiter parameter query using slash (/) would give you

  • photos,
  • movieobject,
  • videos.

The parameter "delimiter" is not supported by the get_objects in the PHP SDK, and using it seems to be the only way to get the base directory files.

There is currently a merge request in github [this request has since been approved] adding this particular parameter to the get_objects method.

Other users of the Rackspace Cloud Files API PHP SDK have also added support for this parameter.

See if the original php-cloudfiles repo gets updated or just create a fork of the original and add your own code, if you don't feel comfortable adding your own changes, clone a fork that has added the delimiter parameter like

https://github.com/michealmorgan/php-cloudfiles or https://github.com/onema/php-cloudfiles

1

The merge request referenced in the answer was approved on May 09, 2012

An optional parameter for get_objects was added for $delimiter ...

enter image description here

However, there was an error introduced into the code at some other point which falsely reports the Container name is not set if one tries to use any of the optional parameters.

A request has been put in to correct this error.

3
  • Nice, didn't know they had approved that merge request :)
    – Onema
    Jul 12, 2012 at 17:45
  • Too bad a bug was introduced if you actually tired to use it! There is a fix here: github.com/rackspace/php-cloudfiles/pull/72 Jul 13, 2012 at 0:33
  • Good to know, I haven't updated to the latest version. but I'll keep an eye on that pull request and get it when it is accepted. So far the request below has been working really well for us.
    – Onema
    Jul 13, 2012 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.