Swift
With the Swift API (an API based on the OpenStack Object Storage API), you can work with object storage resources:
- View information about the number and volume of containers and objects within an account;
- Create and delete containers;
- manage container limits;
- upload, view, copy, move, download, and delete objects in containers.
To access the Swift API, the user must have a role with access to the project in the object store, see the documentation instructions Manage Object Store Access for details.
Authorization
Authorization in the Swift API is done using the IAM token for the project, which is passed in each request in the X-Auth-Token
header.
The address (URL) can be viewed in the URL list.
Example query to view the list of containers in an account project:
curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>'
Specify:
<x_auth_token>
— IAM token for the project;<swift_domain>
— Swift API domain в pool where the object storage is located;<project_id>
— project identifier. You can view the ID in control panel under Object Storage → project menu → Project Management. The identifier is listed under the project name.
Storage
Get storage information
Returns metadata with information about the number and storage capacity of containers and objects.
Example request
curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>'
Example answer
If successful, the request returns a response with code 204.
HTTP/1.1 204 No Content
Content-Length: 0
X-Account-Object-Count: 6
X-Timestamp: 1374058535.42927
X-Account-Meta-Temp-Url-Key: 00000
X-Account-Bytes-Used: 484474
X-Account-Container-Count: 3
X-Account-Meta-<...>: anyheader
X-Openstack-Requiest-Id: 0009ec57-2681-4b48-9105-71c57016edc6
X-Trans-Id: 0009ec57-2681-4b48-9105-71c57016edc6
Response Parameters
Get storage information and container list
Returns storage information and a list of containers.
A single query outputs a list that can contain up to 10,000 containers. If there are more containers, use additional queries with the query parameter marker
.
To get more information about containers (size, update date, etc.), use the query parameter? format=json
.
Example request
curl \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>'
Example answer
container1
container2
container3
Manage storage metadata
Sets, replaces, or removes the metadata passed in the header from the request.
Request headers
Example request
curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Account-Meta-<...>: anyheader' \
'https://<swift_domain>/v1/<project_id>'
Example answer
If successful, the request returns a response with code 204.
Containers
Get container metadata
Outputs container metadata, including the number of objects, storage capacity (in bytes), and container headers.
Example request
curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>'
Example answer
If successful, the request returns a response with code 204.
Get a list of container objects and metadata
Returns the container metadata and outputs a list of objects.
One query outputs a list that can contain up to 10,000 objects. If there are more objects, use additional queries with query-parameters marker и limit
.
Example request
curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>'
Example answer
If successful, the query returns a response with a code 200 or 204.
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Type: text/plain
X-Container-Bytes-Used: 0
X-Container-Meta-Quota-Bytes: 52428800
X-Container-Meta-Quota-Count: 1000
X-Container-Meta-Type: public
X-Container-Object-Count: 1
X-Container-Storage-Policy-Index: 0
X-Container-Storage-Policy-Name: Policy-0
X-Openstack-Request-Id: 585ec880-d654-485f-949e-c0dc24926d00
X-Storage-Policy: Policy-0
X-Timestamp: 1688648194.11923
X-Trans-Id: 585ec880-d654-485f-949e-c0dc24926d00
X-Versions-Enabled: true
Date: Thu, 13 Jul 2023 15:13:53 GMT
Content-Length: 120
Object1
Object2
Object3
Response Parameters
Create a container
Creates a container with the parameters specified in the request.
Request headers
Example request
curl -i -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Container-Meta-Type: public' \
-H 'X-Container-Meta-<...>: anyheader' \
'https://<swift_domain>/v1/<project_id>/<container_name>'
Example answer
If successful, the query returns a response with code 201.
HTTP/1.1 201 Created
Content-Length: 0
Content-Type: text/html
X-Openstack-Requiest-Id: 0009ec57-2681-4b48-9105-71c57016edc6
X-Trans-Id: 0009ec57-2681-4b48-9105-71c57016edc6
Manage container metadata
Sets, replaces, or removes the metadata passed in the header from the request.
Request headers
Example request
Changing the container type:
curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Container-Meta-Type: private' \
-H 'X-Versions-Enabled: true' \
'https://<swift_domain>/v1/<project_id>/<container_name>'
Example answer
If successful, the request returns a response with code 204.
Remove the container
Deletes a container in the repository. Before deleting a container, delete all objects in it.
Example request
curl -i -XDELETE \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>'
Example answer
If successful, the request returns a response with code 204.
HTTP/1.1 204 No Content
Content-Length: 0
Content-Type: Text/html; charset=UTF-8
Objects
Get object
Outputs the body and headers of the object.
Example request
curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>'
Example answer
If successful, the query returns a response with code 200.
Load object
Loads the object into a container. This loading is used for objects up to 100 MB in size. For larger objects, use segmented loading.
When using the X-Copy-From
header, you can load a copied object into a container. The object is copied together with the X-Delete-At
header regardless of where the header was set (to the object or the container).
Request headers
Example request
Loading an object:
curl -i -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Delete-After: 180' \
-d "<object-body>" \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>'
Specify:
<object-body>
— object body;<object_name>
— the name to be assigned to the object.
Copying an object:
curl -i -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Copy-From: /<container_name_1>/<object_name_1>' \
'https://<swift_domain>/v1/<project_id>/<container_name_2>/<object_name_2>'
Specify:
<container_name_2>
— container to which the object will be copied;<object_name_2>
— the name with which the object will be copied;<container_name_1>
— container in which the copied object is located;<object_name_1>
— object to be copied.
Example answer
When loading an object, if successful, the request returns a response with code 201.
HTTP/1.1 201 Created
Content-Length: 0
Content-Type: text/html
Etag: b65ad34618e410d9d8bf624d61f8a980
Date: Thu, 15 Mar 2023 07:31:32 GMT
When copying an object, if successful, the query returns a response with code 201.
HTTP/1.1 201
Created etag: 0f343b0931126a20f133d67c2b018a3b
X-Copied-From: container_name_1/object_name_1
X-Copied-From-Last-Modified: Mon, 27 May 2013 13:16:49 GMT
Last-Modified: Tue, 28 May 2018 06:30:51 GMT
Delete multiple objects
Deletes multiple objects simultaneously, including objects from different containers. Objects are deleted sequentially.