简体   繁体   English

Rackspace-php-opencloud过滤器-有效的ObjectList过滤器的文档?

[英]Rackspace - php-opencloud filters - Documentation for valid ObjectList filters?

Anyone know if/where there is documentation for valid ObjectList filter arrays? 有谁知道/在哪里有关于有效ObjectList过滤器数组的文档?

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. 该项目在github上的条目上有一个很小的内容,将我引向了API文档 ,但这也没有一个完整的列表,并且在“过滤器”上进行的搜索仅涉及容器,而不是对象本身。

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). 使用php-opencloud API,我只想获取其中一种视频格式(以获取唯一的文件名,而不是所有其他格式)。

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? 帮助菜鸟出来吗?

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: 这是php-opencloud文档的当前链接,其中包括一个使用前缀过滤objectList结果的示例:

http://docs.php-opencloud.com/en/latest/services/object-store/objects.html#list-objects-in-a-container 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: 我没有找到有关此文档的文档,但是很显然,当Rackspace Cloud Files文档提到查询字符串中的参数时,这些参数转换为objectList方法调用中的参数,如下所示:

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 ). 不幸的是,底层API不支持对Swift / Cloud Files容器中的对象进行过滤(请参阅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. 共享代码的一部分支持$filter参数,但实际上这里的Cloud Files没有任何作用。

I'll see if I can get the docs updated to reflect that. 我将查看是否可以更新文档以反映这一点。

As Glen's pointed out, there isn't support (at the moment) for the service to apply filters on objects. 正如Glen所指出的那样,该服务目前不支持在对象上应用过滤器。 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. 因此,如果您发送“ bobcatscuddling”作为前缀,则将获得该记录的所有相关视频格式。

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. 您会注意到,您正在增加标记并为每10,000个对象提出一个新请求。 I haven't tested this, but it'll probably lead you in the right direction. 我尚未对此进行测试,但是它可能会引导您朝着正确的方向发展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM