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, more details in the documentation instructions Manage access in object storage.
Authorization
Authorization in the Swift API is performed using X-Auth-Token (scope: project) which is passed in each request in the header X-Auth-Token
.
The address (URL) can be viewed in 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>
-X-Auth-Token (scope: project);<swift_domain>
— Swift API domain в bullet where the object storage is located;<project_id>
— project identifier. You can view the identifier in control panels 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 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.