Selectel Storage (old)
This is an older version of the Selectel Storage API that was in use prior to the object storage update on 09/29/2023. URLs and methods from the old version of the Selectel Storage API are still supported, but will be disabled in the future. We recommend using the new version of the 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 the API are described in the Authorization and obtaining a token section of the Swift API (old) instructions.
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;
- creating 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 need to set the X-Container-Meta-Allow-ZipDownload header : 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 designed primarily 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 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 allow third-party users to download your files (including from personal containers).To create such a link, you do not need to perform an API request.Before generating links to your 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 link of the form https://api.selcdn.ru/v1/SEL_ * **/container_name/object_name
in the above script, the path variable should have the following form**/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
--- 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 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
Special pages
Specialty pages include:
- The index page given in response to an anonymous GET request to a container or folder placed in that container;
- error page (404) --- file given by an anonymous GET request to a non-existent object.
Index page
Request parameters
Both absolute and relative file paths can be specified in the request.
Example request
Create an index file:
echo "<html>custom_index_file</html>" > my_index.html
curl -i -XPUT "https://api.selcdn.ru/v1/SEL_*****/container_name/my_index.html" -H "X-Auth-Token: $token" -T "./my_index.html"
To specify an index page, set the Web-Index value for the container:
curl -i -XPUT "https://api.selcdn.ru/v1/SEL_*****/container_name/my_index.html" \
-H "X-Auth-Token: $token" -H "X-Container-Meta-Web-Index:/my_index.html"
Page 404
Request parameters
Examples
Available template parameters
You can use special template parameters to pass information about the originally requested file:
- {container} --- container name;
- {path} --- the path to the requested file relative to the container.
By default, redirection is performed with the code 307.Available options: 200, 307, 404. When setting an external link, only code 307 is available.
Example request
Set the Web-404-Page value for the container:
curl -i -XPOST "https://api.selcdn.ru/v1/SEL_*****/container_name" -H "X-Auth-Token: $token" \
-H "X-Container-Meta-Web-404-Page: /404.html?file={path}"
An anonymous request for a non-existent object redirects to the specified file:
curl -i "https://api.selcdn.ru/v1/SEL_*****/container_name/non_existing_object" \
> HTTP/1.1 307 Temporary Redirect
> Location: https://api.selcdn.ru/v1/SEL_*****/404.html?file=non_existing_object
By default, a 404 code is returned when submitting an error page:
curl -i -XPOST "https://api.selcdn.ru/v1/SEL_*****/container_name" -H "X-Auth-Token: $token" \
-H "X-Container-Meta-Web-404-Page: /404.html?file={path}?{code}"
File listing
Request parameters
Example request
curl -i -XPOST "https://api.selcdn.ru/v1/SEL_*****/container_name" -H "X-Auth-Token: $token" \
-H "X-Container-Meta-Web-Listings: on"
To retrieve the file listing by anonymous query, type:
curl -i -XGET "https://api.selcdn.ru/v1/SEL_*****/container_name" -H "X-Web-Mode: listing"
To obtain a private container listing, specify the token of the user who has access to the container:
curl -i -XGET "https://api.selcdn.ru/v1/SEL_*****/container_name" -H "X-Auth-Token: $token" -H "X-Web-Mode: listing"
For HTML-formatted output, you can specify the layout using the X-Container-Meta-Web-Listings-Css header, with a reference to a style file in the container as the value; you can also provide a reference to an external style file.
Set the Web-Listings-CSS value for the container:
curl -i -XPOST "https://api.selcdn.ru/v1/SEL_*****/container_name" -H "X-Auth-Token: $token" \
-H "X-Container-Meta-Web-Listings-Css: my_style.css"
User management
Viewing the list of users
Request parameters
Example request
curl -i https://api.selcdn.ru/v1/users -H "X-Auth-Token: $token"
If the request is successful, the API will return a response with code 200.
Example answer
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
Content-Length: 80
main_user (true)
main_user (true)
user1 (true)
user2 (true)
user3 (true)
Adding a new user
Request parameters
Example request
curl -i -XPUT https://api.selcdn.ru/v1/users/my_test_user
-H "X-Auth-Token: $token"
-H "X-Auth-Key: $key"
-H "X-User-ACL-Containers-W: container1, container2, container3"
-H "X-User-ACL-Containers-R: container4"
-H "X-User-S3-Password: yes"
-H "X-User-Active: on"
If the request is successful, the API returns a response with code 204.
Example answer
HTTP/2 204 Created
access-control-allow-origin: *
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Deleting a user
Request parameters
Example request
curl -i -X DELETE https://api.selcdn.ru/v1/users/my_test_user -H "X-Auth-Token: $token"
If the user is successfully deleted, the API returns a response with code 204.
Example answer
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Mon, 19 Mar 2018 10:04:25 GMT
Changing the password of the primary user
Request parameters
Example request
curl -i -XPOST https://api.selcdn.ru/v1/users -H "X-Auth-Token: $token" -H "X-Auth-Key: $key"
If the request is successful, the API returns a response with code 204.
Example answer
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Mon, 19 Mar 2018 10:30:59 GMT
Domain Management
You can attach domains to containers in the repository.All operations with domains are performed via API.
Default Domains
Each object store user automatically gets a set of default domains that can be used to access objects in any containers:
- ********.selcdn.ru ---a domain for public access to files in the storage;
- ********.selcdn.com --- the domain for CDN file sharing over http.
Getting the list of attached domains
Request parameters
Example request
curl -i -XGET https://api.selcdn.ru/v1/domains -H "X-Auth-Token: $token"
If the request is successful, the API returns a response with code 200.
Example answer
HTTP/1.1 200 OK
Content-Length: 69
Content-Type: text/html
Date: Mon, 16 May 2016 07:36:35 GMT
Base Domains:
00000.selcdn.ru
00000.selcdn.com
Containers Domains:
container1 domain1.ru
container2 domain1.ru
Domain attachment
Request parameters
Example request
curl -i -XPOST https://api.selcdn.ru/v1/SEL_*****/container -H "X-Add-Container-Domains: domain1.ru" -H "X-Auth-Token: $token"
If the request is successful, the API will return a response with code 204.
Example answer
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: X-Backend-Timestamp, Etag, Last-Modified, X-Object-Manifest, X-Timestamp
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Tue, 20 Mar 2018 12:09:38 GMT
Domain deletion
Request parameters
Example request
curl -i -XPOST https://api.selcdn.ru/v1/SEL_*****/container -H "X-Remove-Container-Domains: domain1.ru" -H "X-Auth-Token: $token
If the request is successful, the API returns a response with code 204.
Example answer
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: X-Backend-Timestamp, Etag, Last-Modified, X-Object-Manifest, X-Timestamp
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff