Rackspace - php-opencloud filters - Documentation for valid ObjectList filters?

StackOverflow https://stackoverflow.com/questions/18193501

  •  24-06-2022
  •  | 
  •  

문제

Anyone know if/where there is documentation for valid ObjectList filter arrays?

The project's entry on github has a tiny blurb on it directing me to the API documentation, but that also fails to have a comprehensive list, and a search on 'filters' talks about containers only, not the object themselves.

I have a list of videos, each in four different formats named the same thing (sans filetype). Using the php-opencloud API, I want to GET only one of those video formats (to grab the unique filename rather than all its different formats).

I figured using a filter is the way to go, but I can't find any solid documentation.

Someone has got to have done this before. Help a noob out?

도움이 되었습니까?

해결책 2

As Glen's pointed out, there isn't support (at the moment) for the service to apply filters on objects. The only thing which you might be interested in is supplying a prefix, which allows you to refine the objects returned based on how the filenames start. So if you sent 'bobcatscuddling' as the prefix, you'd get back all associated video formats for that one recording.

Your only option, it seems, is to get back all objects and iterate over the collection:

use OpenCloud\Rackspace;

$connection = new Rackspace(RACKSPACE_US, array(
   'username' => 'foo', 
   'apiKey' => 'bar'
)); 
$service = $connection->objectStore('cloudFiles', 'DFW', 'publicURL');

$container = $service->container('CONTAINER_NAME');

$processedObjects = array();
$marker = '';

while ($marker !== null) {

    $objects = $container->objectList('marker' => $marker); 
    $total   = $objects->count();
    $count   = 0;

    while ($object = $objects->next()) {

        // Extract the filename
        $filename = pathinfo($object->name, PATHINFO_FILENAME);

        // Make sure you only deal with the filename once (i.e. to ignore different extensions)
        if (!in_array($processedObjects, $filename)) {

            // You can do your DB check here...

            // Stock the array
            $processedObjects[] = $filename;
        }

        $count++;
        $marker = ($count == $total) ? $object->name : null;
    }

}

What you'll notice is that you're incrementing the marker and making a new request for each 10,000 objects. I haven't tested this, but it'll probably lead you in the right direction.

다른 팁

Most of the links on this page are dead now. Here's a current link to the php-opencloud documentation, which includes an example of using a prefix to filter the objectList results:

http://docs.php-opencloud.com/en/latest/services/object-store/objects.html#list-objects-in-a-container

I didn't find documentation of this, but apparently when the Rackspace Cloud Files documentation mentions arguments in a query string, those translate to arguments in an objectList method call like this:

GET /v1/MossoCloudFS_0672d7fa-9f85-4a81-a3ab-adb66a880123/AppleType?limit=2&marker=grannysmith

equals

$container->objectList(array('limit'=>'2', 'marker'=>'grannysmith'));

Unfortunately, the underlying API doesn't support filtering for objects in Swift/Cloud Files containers (cf. http://docs.rackspace.com/files/api/v1/cf-devguide/content/List_Objects-d1e1284.html). The $filter parameter is supported as part of the shared code, but it doesn't actually do anything with Cloud Files here.

I'll see if I can get the docs updated to reflect that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top