Uploading objects

Once we have created one or more containers, we can start uploading objects to them. While OpenStack Object Storage does not support nested containers, we can simulate folders or file directories with object names. This presents similar structure to the pseudo-folders we used in container names and both achieve similar end goals to a user expecting a tree-like structure to their object storage use.

Getting ready

Ensure that you are logged on to a correctly configured OpenStack client and can access the OpenStack environment as a user with the swiftoperator privileges. We will use the developer user created in the Common OpenStack identity tasks recipe in Chapter 2, The OpenStack Client, with the cookbook4 password; we have also granted this user swiftoperator privileges.

Refer to Chapter 2, The OpenStack Client, for details of setting up your environment to use OpenStack command-line client.

How to do it…

To upload objects to an OpenStack Object Storage container, follow the following steps:

  1. We will upload the intro.txt file into the books container:
    openstack object create books intro.txt
    

    This will give the following output:

    How to do it…
  2. List objects in a container by providing the container name:
    openstack object list books
    

    This will give an output like the following:

    How to do it…

    Note

    Here chapter1 is the pseudo-folder we created in the Creating object containers recipe and it shows as an object.

  3. We can upload an object into the pseudo-folder called books/chapter1 as follows:
    openstack object create books/chapter1 swift.txt
    

    This will give an output like the following:

    How to do it…
  4. To list objects in a container, issue the following against the container name:
    openstack object list books
    

    This will list the objects available under this container:

    How to do it…
  5. To list all objects in the pseudo-folder container name, use a prefix flag:
    openstack object list books --prefix chapter1/
    
    How to do it…

    Tip

    You can use --prefix to list any object that begins with the prefixed letters.

  6. To list all top-level objects in a container, use a delimiter flag. In this example, the delimiter is /:
    openstack object list books --delimiter /
    
    How to do it…
  7. To show information about an object, issue the following command:
    openstack object show books chapter1/swift.txt
    

    This will give information about that object:

    How to do it…

How it works…

In order to store files in OpenStack Object Storage, objects have to be uploaded to a container. Containers cannot be nested; however, pseudo-folders or pseudo-directories can be created using the / delimiter. Once a container is created, you can upload files by using the following command:

openstack object create container_name object_1 [object_2 …]

Tip

Multiple objects can be uploaded with one command.

To list objects that were uploaded to a container, execute the following command:

openstack object list container_name

When listing objects in a container, enable filtering using the --prefix and --delimiter flags.

Note

By default, a maximum of 10,000 objects will be listed. Use pagination or the --all flag to view more than the default number of objects.

To view details of individual object, use the following command:

openstack object show container_name object_name

Note

Regular object size is limited in Swift. By default, only objects 5 GB or smaller can be uploaded with the openstack object create command. Refer to the Uploading large objects recipe on how to upload large objects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.181.196