Get a link to an object
You can:
- get a link to an object in a public bucket — all objects are accessible via public domains of the storage;
- 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 do use Cyrillic, encode the Cyrillic part of the link when working with links to such objects.
Get a link to an object in a public bucket
- In the Control panel, in the top menu, click Products and select S3.
- Go to the Buckets section.
- Open the bucket page → Objects tab.
- In the object row, click .
- In the link row, 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 special bucket
linksas an object with the same name as the object pointed to by the link. Access to the object will be via the public domain of the bucketlinks; - get a temporary link via a presigned URL;
- get a permanent link via a script;
- get 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 accessible at a link like https://<bucket_public_domain>/<object_name>, where:
<bucket_public_domain>— public domain of the bucket;<object_name>— object name.
When you create a link to an object in a private bucket for the first time, a public bucket links is automatically created in the project. The created link is added to it as an object with the same name as the main object. Objects in the bucket links have zero size and do not consume storage volume. If you configure the link as temporary, the object with the link will be automatically deleted from the bucket links when the link expires.
To create a link:
-
In the Control panel, in the top menu, click Products and select S3.
-
Go to the Buckets section.
-
Open the bucket page → Objects tab.
-
In the object's menu, select Open access.
-
Optional: in the Link URL field, change the object name that will be displayed in the link or keep the current one.
-
Optional: to allow following the link only once, select the One-time link checkbox.
-
Optional: to limit the link lifetime, select the Time limits checkbox and select one of the options:
- Delete after — the link will stop working after the selected period of time after creation;
- Delete at specified time — the link will stop working at the selected date and time.
-
Click Create link.
-
To copy the link, click . You can copy it later in the
linksbucket.
Get a temporary link via a signed URL
Using AWS SDK presigned URLs, you can get a temporary link to an object. For more information, see the Sharing objects with presigned URLs guide in the AWS documentation.
Python
PHP
JavaScript
Java
Go
Script example:
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>— value of the Access key field from the S3 key;<secret_key>— value of the Secret key field from the S3 key;<s3_domain>— S3 API domain depending on the pool where the bucket is located;<bucket_name>— bucket name;<path_to_object>— path to the object in the bucket;<time>— link validity period in seconds.
Get a permanent link via a script
Python
PHP
JavaScript
Java
Go
Script example:
import boto3
def get_public_url(bucket_uuid: str, object_key: str) -> str:
return f"https://{bucket_uuid}.selstorage.ru/{object_key}"
if __name__ == "<file_name>":
bucket_uuid = "<uuid>"
object_key = "<path_to_object>"
url = get_public_url(bucket_uuid, object_key)
print("Public URL:", url)
Specify:
<file_name>— Python file name;<uuid>— unique bucket identifier, can be found in the bucket public domain;<path_to_object>— path to the object in the bucket.