Selectel Storage (old)
This is an older version of the Selectel Storage API that was used before object storage updates 29.09.2023. URLs and methods from the old version of the Selectel Storage API continue to be supported for now, but will be disabled in the future. We recommend using new version of Selectel Storage API.
Object Storage provides developers with an opportunity to integrate with their own applications and websites. Interaction with the storage is organized on the basis of REST API. The documentation describes the currently available Storage REST API calls, request and response formats. Currently, the following operations can be performed using REST API requests:
- create links for third-party users to upload files to the repository;
- work with file versions;
- create users and set access settings to the storage for them;
- to download and unzip archives;
- work with special pages, etc.
Methods of authorization and obtaining a token to work with API are described in the section Authorization and token receipt Swift API instructions (old).
Restrictions for additional users
Additional users have limitations when using the API, so the following actions must be performed on behalf of the primary Object Store user:
- container creation;
- deleting multiple files (using
?bulk-delete=true
); - creating or modifying users;
- work with domains and user SSL certificates;
- CDN cache reset;
- log retrieval;
- creation of temporary tokens (
/temptokens
).
Container operations
Creating an image gallery
Request parameters
Example request
curl -i -XPUT https://api.selcdn.ru/v1/SEL_*****/container -H "X-Auth-Token: $token" -H "X-Container-Metatype: gallery"
If the request is successful, the API returns a response with code 204.
Example answer
HTTP/1.1 202 Accepted
Content-Length: 76
Content-Type: text/html; charset=UTF-8
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers:
Downloading the container as a zip archive
The contents of any container can be downloaded as a zip archive. To do this, the query-parameter download-all-as-zip=[archive name] should be added to the link to the container, for example:
wget https://api.selcdn.ru/v1/SEL_*****/container_name/?download-all-as-zip=container_name.zip
In public containers, the zip download functionality is disabled by default, to enable it you must set the header X-Container-Meta-Allow-ZipDownload: true, example:
curl -i -XPUT https://api.selcdn.ru/v1/SEL_***/container_name -H "X-Auth-Token: $token" -H "X-Container-Meta-Allow-ZipDownload: true"
The value of this X-Container-Meta-Allow-ZipDownload header in private containers is ignored.
The following commands can be used to download the contents of any public container as a zip archive:
curl -i -XGET https://api.selcdn.ru/v1/SEL_*****/container?download-all-as-zip=test.zip -o name.zip
The following commands can be used to download the contents of any private container as a zip archive:
curl -i -XGET https://api.selcdn.ru/v1/SEL_*****/container?download-all-as-zip=test.zip -H "X-Auth-Token: $token" -o name.zip
To view the contents of the downloaded archive, use the command:
unzip -l name.zip
Archive: name.zip
warning [name.zip]: 274 extra bytes at beginning or within zipfile (attempting to process anyway)
Length Date Time Name
--------- ---------- ----- ----
555436 1980-00-00 00:00 IMG_20180802_121146.jpg
39 1980-00-00 00:00 copied_file
245473 1980-00-00 00:00 mergetree.pdf
--------- -------
800948 3 files
The described operation is designed primarily to simplify downloading, not to save traffic, so the files in the archive are not compressed.
The number of objects in one container must not exceed 10,000, otherwise the command will fail and return an error.
You can download objects that begin with one specified prefix (for example, IMG) as a zip archive by specifying this IMG prefix in the IMG?download-all-as-zip parameter:
curl -i -XGET https://*****.selcdn.ru/container/?IMG?download-all-as-zip=test.zip -H "X-Auth-Token: $token" -o name.zip
Note: if among the objects there is a folder starting with the same prefix, it will be downloaded together with all its contents.
Downloading the folder as a zip archive
The contents of any folder can be downloaded as a zip archive. To do this, add the query-parameter download-all-as-zip=[archive name] to the link to the folder, for example:
wget https://api.selcdn.ru/v1/SEL_*****/container_name/folder/?download-all-as-zip=container_name.zip
The following commands can be used to download the contents of any folder as a zip archive:
curl -i -XGET https://*****.selcdn.ru/container/folder?download-all-as-zip=test.zip -H "X-Auth-Token: $token" -o name.zip
To view the contents of the downloaded archive, use the command:
unzip -l name.zip
Archive: name.zip
warning [name.zip]: 274 extra bytes at beginning or within zipfile (attempting to process anyway)
Length Date Time Name
--------- ---------- ----- ----
555436 1980-00-00 00:00 IMG_20180802_121146.jpg
39 1980-00-00 00:00 copied_file
245473 1980-00-00 00:00 mergetree.pdf
--------- -------
800948 3 files
The described operation is primarily intended to simplify downloading, not to save traffic, so the files in the archive are not compressed.
The number of objects in one folder must not exceed 10,000, otherwise the command will fail and return an error.
File handling
Unpacking archives
Archives in *.tar, *.tar.gz and *.gzip format can be unpacked immediately after being uploaded to the repository. To unpack an archive, the extract-archive query-parameter must be added to the file download request:
curl -i -XPUT https://api.selcdn.ru/v1/SEL_*****/new_container/archive.tar.gz/?extract-archive=tar.gz \
-H "X-Auth-Token: $token" -T "archive.tar.gz"
Creating a symbolic link to a file
When using storage as a backend for public services, it is often necessary to differentiate access to files --- for example, to make files placed in a private container available to a wide range of users.
Especially for such cases, the repository provides the ability to create symbolic links. Such links can be password-protected and their validity period can be set.
Example request
curl -i -XPUT https://api.selcdn.ru/v1/SEL_*****/new_container/new_link \
-H "X-Auth-Token: $token" -H "Content-Type: x-storage/symlink" \
-H "X-Object-Meta-Location: /new_container/new_object" \
-H "X-Object-Meta-Link-Key: $key" -H "Content-Length: 0"
Example of an answer
HTTP/1.1 201 Created
> etag: d41d8cd98f00b204e9800998ecf8427e
> Last-Modified: Mon, 27 May 2013 13:34:34 GM
Example of X-Object-Meta-Link-Key generation in Python
import hashlib
# location of file, always with container specified
location = "/container/object"
# password
password = "12345"
# concatenate password + location and encode it
encoded_pass_loc = (password + location).encode('utf-8')
# generate sha1-hash
hash_object = hashlib.sha1(encoded_pass_loc)
# convert sha1-hash to hexadecimal digits
link_key = hash_object.hexdigest()
# show calculated value
print(link_key)
Creating a link to download a file
You can create special links that third-party users can use to download your files (including those from personal containers). You do not need to make an API request to create such a link. Before generating links to account files, you need to set the secret key $key:
curl -i -XPOST http://*****.selcdn.ru/ -H "X-Auth-Token: $token" -H "X-Account-Meta-Temp-URL-Key: $key"
To create a link to a specific container, set the secret key $key, adding the container name:
curl -i -XPOST http://*****.selcdn.ru/сontainer -H "X-Auth-Token: $token" -H "X-Container-Meta-Temp-URL-Key: $key"
Only users who know the secret key will be able to access the files using the generated link.
Python example
import hmac
from hashlib import sha1
from time import time
# access method (always GET)
method = "GET"
# reference valid 60 seconds
expires = int(time()) + 60
# the path to the file in the repository, always with the container specified
path = "/container/dir/file"
# secret key
link_secret_key = str.encode("$key")
# generate access key
hmac_body = str.encode('%s\n%s\n%s' % (method, expires, path))
# access key
sig = hmac.new(link_secret_key, hmac_body, sha1).hexdigest()
#show calculated values
print(sig,expires)
When using a reference of the form https://api.selcdn.ru/v1/SEL_***/container_name/object_name
in the above script, the variable path should look like /v1/SEL_***/container_name/object_name
.
The resulting key will then need to be specified in the link:
http://****.selcdn.ru/container/dir/file?temp_url_sig=3f512dfed32111d6e742afc5522076c0621951cc&temp_url_expires=13909142
Where:
*****.selcdn.ru
--- base domain;temp_url_sig
--- access key;temp_url_expires
--- the time until which the link is valid (unixtime).
If the container has a domain attached to it, you can specify it in the link. The name of the container does not need to be specified:
http://my.domain/dir/file?temp_url_sig=3f512dfed32111d6e742afc5522076c0621951cc&temp_url_expires=1390914227
Content-Disposition header control is supported for the data given by the link. To do this, add the filename parameter with the appropriate value:
http://*****.selcdn.ru/container/dir/file?temp_url_sig=3f512dfed32111d6e742afc5522076c0621951cc&temp_url_expires=1390914227&filename=Other+file+name.doc
The secret key can be changed. After changing the secret key, all previously generated links will stop working.
Node.js example
const crypto = require('crypto');
// access method (always GET)
const method = 'GET';
// reference valid 60 seconds
const expires = Math.floor(Date.now() / 1000) + 60;
// the path to the file in the repository, always with the container specified
const path = '/container/dir/file';
// secret key
const linkSecretKey = '$key';
// generate access key
const hmacBody = `${method}\n${expires}\n${path}`;
// access key
const sig = crypto.createHmac('sha1', linkSecretKey).update(hmacBody).digest('hex');
// show calculated values
console.log(sig);
console.log(expires);
Creating a link for downloading files (sendmefile)
Example request
curl -i -XPUT https://api.selcdn.ru/v1/SEL_*****/container/upload \
-H "X-Auth-Token: $token" -H "Content-Type: x-storage/sendmefile+inplace" \
-H "X-Object-Meta-Sendmefile-Max-Size: 52428800" \
-H "X-Delete-After: 14400" \
-H "X-Object-Meta-Sendmefile-Secret: 5baa61e4c9b93f3f0682250b6cf8331b7ee68" \
-d "Пояснительный текст для страницы загрузки"
Versioning
In order to store not only the latest version of an object, but also several previous versions, the repository provides version support.
Before you start working with versioning, create a container to store the versions.
When an object is deleted, the last working version is not returned in its place. All versions of the object, including the one before deletion, are stored in the version container.
Request parameters
Example request
curl -i -XPUT https://api.selcdn.ru/v1/SEL_*****/container1/ -H "X-Auth-Token: $token" -H "X-Versions-Location: container2"
If the request is successful, a response with code 202 will be returned.
Example of an answer
HTTP/1.1 202 Accepted Content-Length: 76
Content-Type: text/html; charset=UTF-8
Access-Control-Allow-Origin: * Access-Control-Expose-Headers: Expires: 0 Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate