Creating a version of an object: Example
The following example can be used to understand how to create object versions.
-
Create a container with the X-Versions-Location header or add the header
to an existing container.
In this example, version_container is the container that holds old versions of objects and container1 is a new or existing container for which object versioning is to be enabled.
swift post -H "X-Versions-Location: version_container" container1
-
Run swift stat on container1 to check that
X-Versions-Location header is applied:
swift stat container1 Account: AUTH_f92886c4e3a347a18c29bae581b36788 Container: container1 Objects: 0 Bytes: 0 Read ACL: Write ACL: Sync To: Sync Key: Accept-Ranges: bytes X-Storage-Policy: Policy-0 Connection: keep-alive X-Timestamp: 1468226043.18746 X-Trans-Id: tx8d17476a914a40d781b0a-0057835a01 Content-Type: text/plain; charset=utf-8 X-Versions-Location: version_container
-
If version_container does not exist, create a new container:
swift post version_container
-
Run swift list at the account level to check that both containers are
created successfully:
swift list container1 version_container
-
Upload an object to container1:
swift upload container1 ImageA.jpg
-
Upload the second version of the object:
swift upload container1 ImageA.jpg
-
Upload the third version of the object:
swift upload container1 ImageA.jpg
-
Run swift list on the container to view the stored object:
swift list container1 ImageA.jpg
Note: The container1 container contains only the most current version of the objects. The older versions of object are stored in version_container. -
Run swift list on version_container to see the older
versions of the object:
swift list version_container 00aImageA.jpg/1468227497.47123 00aImageA.jpg/1468227509.48065
-
To delete the most current version of the object, use the DELETE operation on the object:
swift delete container1 ImageA.jpg ImageA.jpg (deleted latest/third version) # swift list container1 ImageA.jpg (Second version is now the latest version) # swift list version_container 00aImageA.jpg/1468227497.47123 (Initial version of the object)