You can simulate a hierarchical structure in OpenStack Object Storage by following a few
guidelines. Object names must contain the forward slash character / as a
path element separator and also create directory marker objects;
then they will be able to traverse this nested structure with the new
path query parameter. This can best be illustrated by
example:
![]() | Note |
|---|---|
For the purposes of this example, the container where the objects reside is
called |
Example 3.19. Pseudo-Hierarchical Folders/Directories
In the example, the following real objects are uploaded to the storage system with names representing their full filesystem path:
photos/animals/dogs/poodle.jpg
photos/animals/dogs/terrier.jpg
photos/animals/cats/persian.jpg
photos/animals/cats/siamese.jpg
photos/plants/fern.jpg
photos/plants/rose.jpg
photos/me.jpg
To take advantage of this feature, the directory marker
objects must also be created to represent the appropriate directories. The following
additional objects need to be created. A good convention would be to create these as
zero- or one-byte files with a Content-Type of
application/directory.
photos/animals/dogs
photos/animals/cats
photos/animals
photos/plants
photos
Now issuing a GET request against the container name coupled with
the path query parameter of the directory to list can traverse these
directories. Only the request line and results are depicted
below excluding other request/response headers.
GET /v1/AccountString/backups?path=photos HTTP/1.1
Host: storage.swiftdrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
photos/animals
photos/cats
photos/me.jpg
To traverse down into the animals directory, specify that
path.
GET /v1/AccountString/backups?path=photos/animals
Host: storage.swiftdrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
photos/animals/dogs
photos/animals/cats
By combining this path query parameter with the format
query parameter, users will be able to easily distinguish between virtual
folders/directories by Content-Type and build interfaces that allow traversal of the
pseudo-nested structure.
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.
GET /v1/acct/container?delimiter=/
Host: storage.swiftdrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
![[Note]](../common/images/admon/note.png)
