Get a link to an object
You can:
- get a link to an object in a public bucket — all objects are available through public domains of the bucket;
- get a link to an object in a private bucket — the link can be made permanent or temporary.
We do not recommend using Cyrillic in object names. If you use Cyrillic, encode the part of the link with Cyrillic to work with links to such objects.
Get a link to an object in a public bucket
- In the control panel, on the top menu, click Products and select S3.
- Перейдите in раздел Бакеты.
- Откройте страницу бакета → вкладка Объекты.
- In the row with the object, click .
- In the row with the link, click .
Get a link to an object in a private bucket
You can:
- create a permanent or temporary link in the Control panel. The link will be saved in a dedicated
linksbucket as an object with the same name as the object the link points to. You can access the object via the bucket's public domainlinks; - obtain a temporary link via a presigned URL;
- obtain a permanent link via a script;
- obtain a permanent or temporary link using tools, for example Rclone, AWS CLI, Cyberduck, and S3 Browser.
Create a link in the control panel
You can get a temporary or permanent link to an object in a private bucket.
An object in a private bucket will be available via a link like https://<bucket_public_domain>/<object_name>, where:
<bucket_public_domain>— the bucket's public domain;<object_name>— the object name.
Когда вы впервые создаете ссылку on объект in приватном бакете, in проекте автоматически создается публичный бакет links. Созданная ссылка добавляется in него in виде объекта with таким же именем, как у основного объекта. Объекты in бакете links имеют нулевой размер and не потребляют объем хранения. Если вы настроите ссылку как временную, объект со ссылкой автоматически удалится из бакета links, когда ссылка перестанет работать.
To create a link:
-
In the control panel, on the top menu, click Products and select S3.
-
Перейдите in раздел Бакеты.
-
Откройте страницу бакета → вкладка Объекты.
-
In the object menu, select Open access.
-
Optional: in поле Адрес ссылки измените имя объекта, которое будет отображаться in ссылке, or оставьте текущее.
-
Optional: чтобы по ссылке можно было перейти только один раз, отметьте чекбокс Одноразовая ссылка.
-
Optional: to limit the link validity time, select the Time limits checkbox and choose one of the options:
- Delete after — the link will stop working after the specified period of time after creation;
- Delete at specified time — the link will stop working at the selected date and time.
-
Click Create link.
-
Чтобы скопировать ссылку, нажмите . Вы сможете скопировать ее позднее in бакете
links.
Get a temporary link via a presigned URL
С помощью подписанных URL (Presigned URLs) AWS SDK можно получить временную ссылку on объект. Подробнее in инструкции Sharing objects with presigned URLs документации AWS.
Python
PHP
JavaScript
Java
Go
Example script:
import boto3
ACCESS_KEY = "<access_key>"
SECRET_KEY = "<secret_key>"
ENDPOINT_URL = "<s3_domain>"
BUCKET_NAME = "<bucket_name>"
OBJECT_KEY = "<path_to_object>"
EXPIRES_IN = "<time>"
s3 = boto3.client(
"s3",
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
endpoint_url=ENDPOINT_URL,
)
url = s3.generate_presigned_url(
ClientMethod="get_object",
Params={"Bucket": BUCKET_NAME, "Key": OBJECT_KEY},
ExpiresIn=EXPIRES_IN
)
print("\PresignedUrl
:")
print(url)
Specify:
<access_key>— the value of the Access key field from the S3 key;<secret_key>— the value of the Secret key field from the S3 key;<s3_domain>— домен S3 API in зависимости от пула, in котором находится бакет;<bucket_name>— имя бакета;<path_to_object>— путь к объекту in бакете;<time>— время действия ссылки in секундах.
Get a permanent link via a script
Python
PHP
JavaScript
Java
Go
Example script:
import boto3
def get_public_url(bucket_uuid: str, object_key: str) -> str:
return f"https://{bucket_uuid}.selstorage.ru/{object_key}"
if __name__ == "<python_file_name>":
bucket_uuid = "<uuid>"
object_key = "<path_to_object>"
url = get_public_url(bucket_uuid, object_key)
print("Public URL:", url)
Specify:
<python_file_name>— имя файла;<uuid>— the unique bucket identifier, which can be found in the bucket's public domain;<path_to_object>— путь к объекту in бакете.