伪层次结构文件夹和目录

伪层次结构文件夹和目录

尽管不能在OpenStack对象存储做目录嵌套,但可以通过在一个容器对象名称中加入正斜杠(/)来模拟层次结构。如需访问该伪层次结构,可以使用``delimiter``查询参数。这个例子展示了怎样使用伪层次结构的文件夹和目录。

注解

在这个例子中,对象位于名为``backups``的容器中。在该容器中,对象是以伪层次结构组织的,其目录名为``photos``. 容器名在该例中未显示,但会作为URL的一部分。例如``me.jpg``的URL为``https://storage.swiftdrive.com/v1/CF_xer7_343/backups/photos/me.jpg``.

列出伪层次结构目录请求:HTTP

如需列出存储容器中所有对象,使用不带``delimiter``或``prefix``的``GET``请求。

$ curl -X GET -i -H "X-Auth-Token: $token" \
 $publicurl/v1/AccountString/backups

系统返回状态码2xx(200和299之间)和请求的对象列表。

photos/animals/cats/persian.jpg
photos/animals/cats/siamese.jpg
photos/animals/dogs/corgi.jpg
photos/animals/dogs/poodle.jpg
photos/animals/dogs/terrier.jpg
photos/me.jpg
photos/plants/fern.jpg
photos/plants/rose.jpg

使用delimiter参数来缩小结果范围。使用``delimiter``查询伪层次结构时必须使用(/).

$ curl -X GET -i -H "X-Auth-Token: $token" \
 $publicurl/v1/AccountString/backups?delimiter=/

系统返回状态码2xx(200和299之间)和请求的匹配对象。因为使用了斜线,只显示伪目录``photos/``。斜线``delimiter``查询的返回值不是真实对象。如果该返回值不是以斜线结尾的,那么该返回值将引用真正的对象。伪目录不存在content-type,当然,每个伪目录在JSON和XML结果的响应中都有自己的``subdir``条目。比如:

[
   {
     "subdir": "photos/"
   }
 ]

 [
   {
     "subdir": "photos/animals/"
   },
   {
     "hash": "b249a153f8f38b51e92916bbc6ea57ad",
     "last_modified": "2015-12-03T17:31:28.187370",
     "bytes": 2906,
     "name": "photos/me.jpg",
     "content_type": "image/jpeg"
   },
   {
     "subdir": "photos/plants/"
   }
 ]
<?xml version="1.0" encoding="UTF-8"?>
 <container name="backups">
   <subdir name="photos/">
     <name>photos/</name>
   </subdir>
 </container>

 <?xml version="1.0" encoding="UTF-8"?>
 <container name="backups">
   <subdir name="photos/animals/">
     <name>photos/animals/</name>
   </subdir>
   <object>
     <name>photos/me.jpg</name>
     <hash>b249a153f8f38b51e92916bbc6ea57ad</hash>
     <bytes>2906</bytes>
     <content_type>image/jpeg</content_type>
     <last_modified>2015-12-03T17:31:28.187370</last_modified>
   </object>
   <subdir name="photos/plants/">
     <name>photos/plants/</name>
   </subdir>
 </container>

使用` 前缀 分隔符 `参数查看对象在一个伪目录,包括进一步的嵌套伪目录。

$ curl -X GET -i -H "X-Auth-Token: $token" \
 $publicurl/v1/AccountString/backups?prefix=photos/&delimiter=/

系统返回状态码2xx(200和299之间)和最高层中的伪目录对象以及伪目录。

photos/animals/
photos/me.jpg
photos/plants/

可以创建无限制数目的嵌套伪目录。为了浏览这些嵌套的伪目录,请使用更长的``prefix``参数和``delimiter``参数。在这个实例输出中,伪目录``animals``中有一名为``dogs``的伪目录。为直接访问``dogs``中包含的文件,请输入如下的命令:

$ curl -X GET -i -H "X-Auth-Token: $token" \
 $publicurl/v1/AccountString/backups?prefix=photos/animals/dogs/&delimiter=/

系统返回状态码2xx(200和299之间)和嵌套伪目录中的对象以及伪目录。

photos/animals/dogs/corgi.jpg
photos/animals/dogs/poodle.jpg
photos/animals/dogs/terrier.jpg
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.