OpenStack4j > Documentation / Object Storage (Swift)

Object Storage (Swift)

Swift is a highly available, distributed, eventually consistent object/blob store. Organizations can use Swift to store lots of data efficiently, safely, and cheaply.


An account is also known as a project or tenant. An account is the security profile in which containers and objects live. Due to the role of an account there are not many management tasks associated with it.

Getting the Account Details

To retrieve account details see the example below:

SwiftAccount account = os.objectStorage().account().get();


Creating or Updating Metadata for an Account

boolean successful = os.objectStorage().account().updateMetadata(myMetadataMap);

Removing Metadata items for an Account

boolean successful = os.objectStorage().account().deleteMetadata(myMetadataMap);


A container is essentially a bucket of objects. Containers can have access security assigned to them, published against a CDN or be shared publicly.

Querying for Containers

Listing all Containers the current Account

List<? extends SwiftContainer> containers = os.objectStorage().containers().list();

Querying with advanced criteria

List<? extends SwiftContainer> containers = os.objectStorage()
                                                      // ...

Creating a Container

// Simple
// Full control
os.objectStorage().containers().create("myContainer", CreateUpdateContainerOptions.create()
                                                       ); #### Updating a Container

Updating a container is very simular to creating one like the above “full control” example. The only differences is the method call. See brief example:

os.objectStorage().containers().update("myContainer", CreateUpdateContainerOptions);

Deleting a Container

Note, in order to successfully reemove a container it must be empty. This is not an OpenStack4j policy but a requirement by OpenStack.


Creating Pseudo Directories

Depending on how your deployment is configured this feature may/may not be supported. Vendors such as Rackspace support this out of the box.

os.objectStorage().containers().createPath(containerName, "/my/nested/path");


Fetching Metadata

Map<String, String> md = os.objectStorage().containers().getMetadata(containerName);

Creating or Updating Metadata

boolean successful = os.objectStorage().containers().updateMetadata(containerName, myMetadataMap);

Removing Metadata items

boolean successful = os.objectStorage().containers().deleteMetadata(containerName, myMetadataMap);


Objects are uploaded files, manifestations or pseudo directories. Objects are associated to a container.

Querying for Objects

Listing all Objects for a Container

List<? extends SwiftObject> objs = os.objectStorage().objects().list(containerName);

Querying with advanced criteria

List<? extends SwiftObject> objs = os.objectStorage().objects().list(ObjectListOptions.create()
                                        // ...

Creating Objects


String etag = os.objectStorage().objects().put(containerName, objectName, Payloads.create(someFile));


String etag = os.objectStorage().objects().put(containerName, objectName, 
                                                  // ...

Deleting an Object

os.objectStorage().objects().delete(containerName, objectName);

Copying an Object

String etag = os.objectStorage().objects().copy(ObjectLocation.create(srcContainer, srcObject)
                                                ObjectLocation.create(destContainer, destObject)


Fetching Metadata

Map<String, String> md = os.objectStorage().objects().getMetadata(containerName, objectName);

Creating or Updating Metadata

boolean successful = os.objectStorage().objects().updateMetadata(ObjectLocation.create(containerName, objectName), myMetadataMap);