Get a reference to an object
You can:
- get a reference to an object in the public bucket — all objects are available through public domains repositories;
- get a link to an object in a private bucket — The link can be made permanent or temporary.
We do not recommend using Cyrillic characters in object names. If you use Cyrillic, encode the Cyrillic part of the reference to work with references to such objects.
Get a reference to an object in a public baket
- In the control panel, on the top menu, click Products and select S3.
- Go to the Buckets section.
- Open the baket page → Objects tab.
- On the line with the object, click.
- On the link line, click.
Get a link to an object in a private bucket
You can:
- create a permanent or temporary link in the control panel — the object will be accessible via a link through the public domain of the bucket;
- get a temporary link via a signed URL;
- get a permanent link through a script;
- Get a permanent or temporary link through tools such as 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 by a link of the form https://<bucket_public_domain>/<object_name>, where:
<bucket_public_domain>— bucket public domain;<object_name>— object name.
When you first create a link to an object in a private bucket, a public links bucket 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 links bucket have zero size and do not consume any storage space. If you configure a link as temporary, the object with the link will be automatically removed from the links bucket when the link stops working.
To create a link:
-
In the control panel, on the top menu, click Products and select S3.
-
Go to the Buckets section.
-
Open the baket page → Objects tab.
-
From themenu of the object, select Open Access.
-
Optional: in the Link Address field, change the name of the object to be displayed in the link, or leave the current one.
-
Optional: to allow the link to be clicked only once, check the One-time link checkbox.
-
Optional: to limit the time the link is valid, check the Time Limits checkbox and select one of the options:
- Delete via — link will stop working after the selected time interval after creation;
- Delete at a specified time — the link will stop working on the selected date and time.
-
Click Create Link.
-
To copy a link, click. You can copy it later in the
linkspackage.
Get a temporary link via a signed URL
You can use AWS SDK Presigned URLs to get a temporary reference to an object. For more information, see the Sharing objects with presigned URLs in the AWS documentation.
Python
PHP
JavaScript
Java
Go
Sample 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>— field value Access key from S3 key;<secret_key>— field value Secret key from S3 key;<s3_domain>— S3 API domain depending on the pool in which the bucket is located;<bucket_name>— bucket name;<path_to_object>— path to the object in the baket;<time>— link validity time in seconds.
Sample script:
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
$servercoreS3 = new S3Client([
'version' => 'latest',
'region' => '<pool>',
'endpoint' => '<s3_domain>':,
'use_path_style_endpoint' => true,
'credentials' => [
'key' => '<access_key>',
'secret' => '<secret_key>',
],
]);
$bucket = '<bucket_name>';
$key = '<path_to_object>';
try {
$cmd = $servercoreS3->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => $key
]);
$request = $servercoreS3->createPresignedRequest($cmd, '<time>');
$presignedUrl = (string)$request->getUri();
echo "Публичная ссылка: $presignedUrl\n";
} catch (AwsException $e) {
echo "Ошибка генерации ссылки: " . $e->getMessage() . "\n";
}
Specify:
<pool>— pool where the buckets are located;<s3_domain>— S3 API domain depending on the pool in which the bucket is located;<access_key>— field value Access key from S3 key;<secret_key>— field value Secret key from S3 key;<bucket_name>— bucket name;<path_to_object>— path to the object in the baket;<time>— link validity time, e.g.+1 hour.
Sample script:
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const client = new S3Client({
region: "<pool>",
endpoint: "<s3_domain>",
forcePathStyle: true,
credentials: {
accessKeyId: "<access_key>",
secretAccessKey: "<secret_key>",
},
});
async function generatePresignedUrl() {
const bucket = "<bucket_name>";
const key = "<path_to_object>";
const command = new GetObjectCommand({ Bucket: bucket, Key: key });
const url = await getSignedUrl(client, command, { expiresIn: <time> });
console.log("Presigned URL:", url);
}
generatePresignedUrl().catch(console.error);
Specify:
<pool>— pool where the buckets are located;<s3_domain>— S3 API domain depending on the pool in which the bucket is located;<access_key>— field value Access key from S3 key;<secret_key>— field value Secret key from S3 key;<bucket_name>— bucket name;<path_to_object>— path to the object in the baket;<time>— link validity time in seconds.
Sample script:
package com.example;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest;
import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest;
import java.net.URI;
import java.time.Duration;
public class ServercoreS3PresignedUrlGenerator {
public static void main(String[] args) {
String endpoint = "<s3_domain>";
String region = "<pool>";
String accessKey = "<access_key>";
String secretKey = "<secret_key>";
String bucketName = "<bucket_name>";
String objectKey = "<path_to_object>";
StaticCredentialsProvider credentials = StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
);
S3Client s3Client = S3Client.builder()
.endpointOverride(URI.create(endpoint))
.region(Region.of(region))
.credentialsProvider(credentials)
.build();
S3Presigner presigner = S3Presigner.builder()
.endpointOverride(URI.create(endpoint))
.region(Region.of(region))
.credentialsProvider(credentials)
.build();
try {
GetObjectRequest getObjectRequest = GetObjectRequest.builder()
.bucket(bucketName)
.key(objectKey)
.build();
GetObjectPresignRequest presignRequest = GetObjectPresignRequest.builder()
.signatureDuration(Duration.ofMinutes(<time>))
.getObjectRequest(getObjectRequest)
.build();
PresignedGetObjectRequest presignedRequest = presigner.presignGetObject(presignRequest);
System.out.println("Presigned URL: " + presignedRequest.url());
System.out.println("Expires at: " + presignedRequest.expiration());
} catch (S3Exception e) {
System.err.println("Ошибка при генерации presigned URL: " + e.awsErrorDetails().errorMessage());
} finally {
s3Client.close();
presigner.close();
}
}
}
Specify:
<s3_domain>— S3 API domain depending on the pool in which the bucket is located;<pool>— pool where the buckets are located;<access_key>— field value Access key from S3 key;<secret_key>— field value Secret key from S3 key;<bucket_name>— bucket name;<path_to_object>— path to the object in the baket;<time>— link validity time in minutes.
Sample script:
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
func main() {
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithCredentialsProvider(
credentials.NewStaticCredentialsProvider("<access_key>", "<secret_key>", ""),
),
)
if err != nil {
log.Fatal(err.Error())
}
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
o.BaseEndpoint = aws.String("<s3_domain>")
o.Region = "<pool>"
})
presignClient := s3.NewPresignClient(client)
req, err := presignClient.PresignGetObject(context.TODO(), &s3.GetObjectInput{
Bucket: aws.String("<bucket_name>"),
Key: aws.String("<path_to_object>"),
}, s3.WithPresignExpires(<time>))
if err != nil {
log.Fatal(err.Error())
}
fmt.Println("Публичная ссылка:", req.URL)
}
Specify:
<access_key>— field value Access key from S3 key;<secret_key>— field value Secret key from S3 key;<s3_domain>— S3 API domain depending on the pool in which the bucket is located;<pool>— pool where the buckets are located;<bucket_name>— bucket name;<path_to_object>— path to the object in the baket;<time>— link validity time, e.g.24*time.Hour.
Get a permanent link through a script
Python
PHP
JavaScript
Java
Go
Sample 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>— file name;<uuid>— unique identifier of the bucket, can be viewed in the bucket's public domain;<path_to_object>— path to the object in the baket.
Sample script:
<?php
function get_public_url(string $bucket_uuid, string $object_key): string {
return "https://{$bucket_uuid}.selstorage.ru/{$object_key}";
}
$bucket_uuid = "<uuid>";
$object_key = "<path_to_object>";
$public_url = get_public_url($bucket_uuid, $object_key);
echo "Public URL: " . $public_url . PHP_EOL;
Specify:
<uuid>— unique identifier of the bucket, can be viewed in the bucket's public domain;<path_to_object>— path to the object in the baket.
Sample script:
function getPublicUrl(bucketUuid, objectKey) {
return `https://${bucketUuid}.selstorage.ru/${objectKey}`;
}
const bucketUuid = "<uuid>";
const objectKey = "<path_to_object>";
const publicUrl = getPublicUrl(bucketUuid, objectKey);
console.log("Public URL:", publicUrl);
Specify:
<uuid>— unique identifier of the bucket, can be viewed in the bucket's public domain;<path_to_object>— path to the object in the baket.
Sample script:
public class ServercorePublicLink {
public static String getPublicUrl(String bucketUuid, String objectKey) {
return "https://" + bucketUuid + ".selstorage.ru/" + objectKey;
}
public static void main(String[] args) {
String bucketUuid = "<uuid>";
String objectKey = "<path_to_object>";
String publicUrl = getPublicUrl(bucketUuid, objectKey);
System.out.println("Public URL: " + publicUrl);
}
}
Specify:
<uuid>— unique identifier of the bucket, can be viewed in the bucket's public domain;<path_to_object>— path to the object in the baket.
Sample script:
package main
import (
"fmt"
)
func getPublicURL(bucketUUID, objectKey string) string {
return fmt.Sprintf("https://%s.selstorage.ru/%s", bucketUUID, objectKey)
}
func main() {
bucketUUID := "<uuid>"
objectKey := "<path_to_object>"
publicURL := getPublicURL(bucketUUID, objectKey)
fmt.Println("Public URL:", publicURL)
}
Specify:
<uuid>— unique identifier of the bucket, can be viewed in the bucket's public domain;<path_to_object>— path to the object in the baket.