Using containers

There are several different methods available to you for interacting with the object storage service. The following sections cover the most common tools that people use. Each of these examples shows some of the basic commands that you can use to create and edit your object storage containers.

Via the dashboard

When using the object storage service, your data must be stored in a container (also referred to as a bucket.) So our first step is to create at least one container prior to uploading any data. To create a new container, navigate to the “Containers” section on the dashboard and click “Create Container”.

../_images/containers_ui.png

You will need to provide a name for the container as well as select the appropriate access level and replication policy type before clicking “Submit”.

Warning

Please do not use an underscore “_” when naming your container. The reasoning for this is explained in the programmatic examples below.

Note

Setting “Public” level access on a container means that anyone with the container’s URL can access the contents of that container.

../_images/create_container.png

You should now see the newly created container. As this is a new container, it currently does not contain any data. Click on the upload button next to “Folder” to add some content.

../_images/new_container.png

Click on the “Browse” button to select the file you wish to upload and once selected click “Upload File”.

../_images/doing_upload.png

In the containers view the Object Count has gone up to one and the size of the container is now 5 Bytes.

../_images/uploaded_file.png

Via programmatic methods

Prerequisites

For several of the methods detailed below, you will have to prepare your command line environment before continuing with the examples. The key things that need to be prepared are:

  • You must Source an OpenRC file.

  • You must ensure that you have the correct role for using object storage on your cloud project. See here for more details.

Once you have met these requirements, you can continue with any of the method you below:

Warning

Please do not use an underscore “_” when naming your containers. This will cause an error with the S3 api and you will receive errors through your CLI when using this method. As a general practice we recommend avoiding the use of an underscore regardless of the method you choose below.


The following is a list of the most commonly used commands that will help you interact with the object storage service via the openstack command line.


To view the current containers on your project, you can use the openstack container list command:

$ openstack container list
mycontainer-1
mycontainer-2

To view the objects stored within a container: openstack object list <container_name>

$ openstack object list mycontainer-1
+-------------+
| Name        |
+-------------+
| file-1.txt  |
| image-1.png |
+-------------+

To create a new container: openstack container create <container_name>

$ openstack container create mynewcontainer

+---------+----------------+----------------------------------------------------+
| account | container      | x-trans-id                                         |
+---------+----------------+----------------------------------------------------+
| v1      | mynewcontainer | tx000000000000000146531-0057bb8fc9-2836950-default |
+---------+----------------+----------------------------------------------------+

To add a new object to a container: openstack object create <container_name> <file_name>

$ openstack object create mynewcontainer hello.txt

+-----------+----------------+----------------------------------+
| object    | container      | etag                             |
+-----------+----------------+----------------------------------+
| hello.txt | mynewcontainer | d41d8cd98f00b204xxxxxx98ecf8427e |
+-----------+----------------+----------------------------------+

To delete an object from a container: openstack object delete <container> <object>

$ openstack object delete mynewcontainer hello.txt

To delete a container: openstack container delete <container>

Note

this will only work if the container does not contain any objects.

$ openstack container delete mycontainer-1

To delete a container and all of the objects within the container: openstack container delete --recursive <container>

$ openstack container delete --recursive mycontainer-1