Skip to main content

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

ParameterSignificance
X-Account-Bytes-Used.Total amount of data stored (in bytes)
X-Account-Container-CountNumber of containers
X-Account-Meta-&lt;...>Metadata where &lt;...> — custom header
X-Account-Meta-Temp-Url-KeyA secret key that is used to access objects in the private container via a temporary URL (if available)
X-Account-Object-CountTotal number of stored objects
X-Account-Storage-Policy-Policy-0-Bytes-UsedThe total amount of data stored by storage policy, where Policy-0 is the name of the policy
X-Account-Storage-Policy-Policy-0-Container-CountThe number of containers that use the storage policy, where Policy-0 is the policy name
X-Account-Storage-Policy-Policy-0-Object-CountThe number of objects that use the storage policy, where Policy-0 is the policy name
X-Openstack-Request-Id.
X-Trans-Id
request ID
X-TimestampThe date and time, in UNIX format, when the account, container, or object was created
DateDate and time the request was sent

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

CaptionDescription
X-Account-Meta-&lt;...>Storage metadata to be set where &lt;...> — custom header
X-Remove-Account-Meta-&lt;...>Storage metadata that needs to be deleted where &lt;...> — custom header

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

HEAD/v1/{project_id}/{container_name}Retrieving container metadata
GET/v1/{project_id}/{container_name}Getting the list of objects and metadata of the container
PUT/v1/{project_id}/{container_name}Container creation
POST/v1/{project_id}/{container_name}Managing container metadata
DELETE/v1/{project_id}/{container_name}Removing a container

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

ParameterSignificance
X-Container-Object-CountNumber of objects in a container
X-Container-Bytes-Used.Volume of objects in the container (in bytes)
X-Container-Meta-TypeContainer type
X-Container-Meta-Quota-BytesMaximum data storage capacity (in bytes)
X-Container-Meta-Quota-Count.Maximum number of objects in a container
X-Container-Meta-&lt;... ...>Container metadata where &lt;...> — custom header
X-Versions-EnabledWhether container versioning is enabled

Create a container

Creates a container with the parameters specified in the request.

Request headers

CaptionDescription
X-Container-Meta-TypeContainer Type:
  • public;
  • private
X-Container-Meta-&lt;... ...>Container metadata. Specify \\<...> — metadata header
X-Storage-PolicyStorage Class:
  • Policy-0 (default) is the default storage;
  • cold storage
X-Versions-EnabledWhether container versioning is enabled
X-Container-Meta-Default-Delete-After.Storage time of all objects in the container (in seconds)

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

TitleDescription
X-Container-Meta-TypeContainer Type:
  • public;
  • private
X-Container-Meta-&lt;... ...>Container metadata to be set where &lt;...> — custom header
X-Remove-Container-Meta-&lt;... ...>Container metadata that needs to be deleted, where &lt;...> — custom header
X-Versions-EnabledWhether container versioning is enabled

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/v1/{project_id}/{container_name}/{object_name}Obtaining an object
PUT/v1/{project_id}/{container_name}/{object_name}Loading an object
POST/v1/{project_id}Deleting multiple objects
POST/v1/{project_id}/{container_name}/{object_name}Managing HTTP headers and object metadata
COPY/v1/{project_id}/{container_name}/{object_name}Copying an object
DELETE/v1/{project_id}/{container_name}/{object_name}Deleting an object

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 header X-Copy-From you can load the copied object into the container. The object is copied together with the header X-Delete-At regardless of where the header was set (on the object or container).

Request headers

TitleDescription
X-Delete-AtTime of object deletion in Unix Timestamp format
X-Delete-AfterObject storage time (in seconds)
EtagEtag ID
X-Object-Meta-&lt;...>The metadata of the object, where &lt;...> — custom header
X-Copy-FromPath to the object to be copied

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> — the body of the object;
  • <object_name> — 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 into which the object will be copied;
  • <object_name_2> — name with which the object will be copied;
  • <container_name_1> — container where the object to be copied 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.

Example request

Deleting objects from different containers:

curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'Content-Type: text/plain' \
-d $'<container_name_1>/<object_name_1>\n<container_name_2>/<object_name_2>' \
'https://<swift_domain>/v1/<project_id>?bulk-delete=true&format=json'

Specify:

  • <container_name_1>/<object_name_1> — path to the object in the first container;
  • <container_name_2>/<object_name_2> — path to the object in the second container;
  • \n — line break, must be specified between objects.

Example answer

If successful, the query returns a response with code 200.

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Fri, 08 Jun 2018 13:37:53 GMT
Content-Length: 101
{'Number Not Found':0,'Response Status':'200 OK','Response Body':'','Errors':null,'Number Deleted':2}

Manage HTTP headers and object metadata

Sets values for the user and HTTP headers specified in the request. Headers are used to control client-side caching and intermediate proxy servers.

Supported HTTP headers:

  • Cache-Control
  • Content-Encoding
  • Content-Type
  • Content-Disposition
  • Link

Request headers

TitleDescription
X-Container-Meta-&lt;... ...>The title to be set. Specify&lt;...> — header (for example, X-Container-Meta-Cache-Control)

Example request

Adding a header Link to the subject:

curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'Link: rel=canonical' \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>'

Adding a custom header:

curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Object-Meta-Some: metadata' \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>'

Example answer

Request to add a header Link if successful, returns a response with code 202.

HTTP/1.1 202 Accepted
Content-Length: 76
Content-Type: text/html

The request to add a custom header, if successful, returns a response with code 201.

HTTP/1.1 201 Created
Content-Length: 0
Content-Type: text/html
Etag: d41d8cd98f00b204e9800998ecf8427e

Copy object

The object will be copied to a different container or by a different prefix. If for a header X-Fresh-Metadata set the value trueWhen copying, a new object will be created with new headers, including without X-Delete-At.

Request headers

TitleDescription
DestinationPath where the object will be copied

Example request

curl -i -XCOPY \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'Destination: /<container_name_2>/<object_name_2>' \
'https://<swift_domain>/v1/<project_id>/<container_name_1>/<object_name_1>'

Specify:

  • <container_name_1> — container where the object to be copied is located;
  • <object_name_1> — object to be copied.
  • <container_name_2> — container into which the object will be copied;
  • <object_name_2> — name with which the object will be copied.

Example answer

If successful, the query returns a response with code 201.

HTTP/1.1 201
Created etag: 0f343b0931126a20f133d67c2b018a3b
X-Copied-From: container1/file
X-Copied-From-Last-Modified: Mon, 27 May 2013 13:16:49 GMT
Last-Modified: Tue, 28 May 2013 06:30:51 GMT

Delete object

The object will be removed from the container.

To delete a segmented object, use the query parameter ?multipart-manifest=delete — object segments and manifest will be deleted.

Example request

curl -i -XDELETE \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_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

Headers for deferred deletion

Headers are specified when sending PUT and POST requests and determine when an object will be automatically removed from the repository.

TitleValueDescription
X-Delete-AtTimestamp value in Unix Epoch formatThe server will store the object until the time passed in the header. To convert to human-readable form you can use EpochConverter.
X-Delete-AfterInteger number of secondsThe server converts this value into an X-Delete-At header. After the specified number of seconds, the request will start returning a 404 response to the object request, with the objects automatically deleted after a certain amount of time.

If both headers are specified, the priority will be given to the header X-Delete-After.

Features how headings work:

  • if the object is loaded with a PUT request and header X-Delete-Atand the container has a modified header, the object header will be overwritten by the container header;
  • if versioning is enabled in the container, headers X-Delete-At и X-Delete-After are not transferred to the created version. The loaded version will not be deleted, but the object will disappear from the list.

Segmented objects

The repository has no restrictions on the size of uploaded objects, but objects larger than 100 MB are not recommended to be placed in the repository in their entirety — it is necessary to split the object into segments, upload each segment of the object and a manifest file uniting all segments of the object (DLO/SLO technology). For more information about loading segmented objects, see the documentation instructions Load object.

When using segmented loading, two types of large objects can be loaded:

  • dynamic (DLO), you must specify the container and segment prefix when loading the manifest of a dynamic object. You can load and delete individual segments without having to change the manifest file;
  • static (SLO), when loading the manifest of a static object, the path to each segment that makes up the object is specified. Each time the segments are changed, the manifest file must be edited and loaded again. Optionally, you can specify checksums (Etag) and size for segments.

To retrieve the manifest file, execute GET request to get an object query-parameter ?multipart-manifest=get.

You can delete all segments and the object with the manifest using DELETE request query-parameter ?multipart-manifest=delete.

Load object segments

We recommend downloading segments first before creating or updating the manifest. Until all segments have finished downloading, the object will not be available for download.

Example of requests

curl -i -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-d "hello " \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>/00000001'

curl -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-d "world" \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>/00000002'

curl -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-d "!" \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>/00000003'

Example answer

If successful, the queries return responses with code 201.

Load the dynamic object manifest

Example request

curl -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Object-Manifest: <container_name>/<object_name>/' \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>'

Example answer

If successful, the query returns a response with code 201.

Load static object manifest

Example request

In the body of the static object manifest, specify the path to each segment of the object.

curl -XPUT \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Static-Large-Object: True' \
"[{"path": "/<container_name>/<object_name>/00000001"}, {"path": "/<container_name>/<object_name>/00000002"}, {"path": "/<container_name>/<object_name>/00000003"} ...]" \
'https://<swift_domain>/v1/<project_id>/<container_name>/<object_name>?multipart-manifest=put'

Example answer

If successful, the query returns a response with code 201.

Limits

POST/v1/{project_id}/{container_name}Setting container limits
POST/v1/{project_id}Setting project limits

Set container limits

Sets the constraints passed in the headers to the container X-Container-Meta-Quota-Bytes и X-Container-Meta-Quota-Count.

Request headers

TitleDescription
X-Container-Meta-Quota-BytesMaximum data storage capacity (in bytes)
X-Container-Meta-Quota-Count.Maximum number of objects in a container
X-Container-Meta-Default-Delete-After.The retention period for all objects in the container (in seconds). After this period expires, the objects will be automatically deleted

Example request

curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Container-Meta-Quota-Bytes: 52428800' \
-H 'X-Container-Meta-Quota-Count: 1000' \
-H 'X-Container-Meta-Default-Delete-After: 300' \
'https://<swift_domain>/v1/<project_id>/<container_name>'

Example answer

If the request is successful, a response with code 202 will be returned.

HTTP/1.1 202 Accepted
Content-Length: 76
Content-Type: text/html

Set project limits

Sets the constraint passed in the header to the project X-Account-Meta-Quota-Bytes.

Request headers

TitleDescription
X-Container-Meta-Quota-BytesMaximum data storage capacity (in bytes)

Example request

curl -i -XPOST \
-H 'X-Auth-Token: <x_auth_token>' \
-H 'X-Account-Meta-Quota-Bytes: 52428800' \
'https://<swift_domain>/v1/<project_id>'

Example answer

If the request is successful, a response with code 202 will be returned.

HTTP/1.1 202 Accepted
Content-Length: 76
Content-Type: text/html

Additional query parameters

In a request for container list retrieval or facilities additional query-parameters can be used.

format

Will return a list of objects in a specific format.

Example of a request:

curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>?format=json'

The list of objects will be returned in JSON format.

limit

Specifies the exact number of objects to be included in the list (for example, when working with containers that store a large number of objects).

Example of a request:

curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>?limit=20'

The list will include the first 20 sites.

marker

Specifies the object starting from which the list will be displayed.

Example of a request:

curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>?marker=<object_name>'

The list will display the objects that follow the object <object_name>.

prefix

Will include in the list objects whose names begin with the specified sequence of characters.

Example of a request:

curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>?prefix=my'

The list will show objects that start with the characters my.

delimiter

The object store has a flat structure and does not support folders, but with the parameter delimiter you can output a pseudo-hierarchy. A query with a parameter will output only the part of the object name that follows the specified characters, if it is present in the object name output.

Example of a request:

curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>?delimiter=/'

The files and parts of the prefixes (pseudo folders) at the top level will be output:

photos/
videos/
file.jpg

Here:

  • photos/, videos/ — prefixes before the character /that the objects in the container have;
  • file.jpg — file without a prefix (character / in the title).

Parameter delimiter can be used in conjunction with the parameter prefixto output a list of objects and pseudo-folders by the specified prefix.

Example of a request:

curl -i \
-H 'X-Auth-Token: <x_auth_token>' \
'https://<swift_domain>/v1/<project_id>/<container_name>?prefix=photos/&delimiter=/'

Example output:

photos/animals/
photos/file.jpg

A symbolic link is an empty object that points to another object. They can be used to access objects in another container:

  • with a different storage policy — for example, to access an object in a container with cold storage from a container with standard storage;
  • with another type — for example, to access an object in a private container via a symbolic link placed in a public container.

You can create a symbolic link using an empty PUT request to load an object titled X-Symlink-Target: <container_name>/<object_name>.

By default, symbolic links are dynamic — they refer to an object by its name. A symbolic link can be made static: when you follow the link, the Etag of the object is additionally checked. To do this, add a header to the request X-Symlink-Target-Etag: <etag>.

If the referenced object is non-empty, the query will return a response of 400.

To retrieve an object with a symbolic link, perform a GET or HEAD request with a parameter ?symlink=get.