Presigned URLs
Note: Sonic's S3 API is not yet compatible with AWS S3 signature of type STREAMING-UNSIGNED-PAYLOAD-TRAILER, causing Boto3 >= 1.36.0 and AWS CLI >= 2.14.0 to corrupt files during upload. Please check your versions before proceeding.
Presign an URL
Sonic supports presigned URLs for object uploads. This allows you to generate secure URLs for direct file uploads, eliminating the need for your application servers to handle the data. In this example, we are running in a virtual Python environment to avoid Debian/Ubuntu errors and are using Boto3 to generate a URL.
# Create a fresh env
python3 -m venv ~/presign-venv# Activate it
source ~/presign-venv/bin/activate# Install Boto3
pip install "boto3==1.35.*" "botocore==1.35.*"In your application:
import boto3
from botocore.config import Config
ACCESS_KEY = "your_access_key"
SECRET_KEY = "your_secret_key"
session = boto3.session.Session(
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
region_name="us-east-1", # region just scopes the SignatureV4; Otherwise not needed for Sonic
)
s3 = session.client(
"s3",
endpoint_url="https://s3.eu-central.r-cdn.com",
config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),
)
bucket = "your_bucket_id"
key = "example.txt"
content_type = "text/plain"
put_url = s3.generate_presigned_url(
ClientMethod="put_object",
Params={"Bucket": bucket, "Key": key, "ContentType": content_type},
ExpiresIn=3600,
)
print("PUT URL:\n", put_url)Example response
PUT URL:
https://s3.eu-central.r-cdn.com/5682/example.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=FSCIDQAGGF8EDQFFBJOZI%2F20250930%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250930T093646Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Signature=c8097d1e2bb2aea5acfeacf63826fc20a68897d4322768e39ae548cbbf6dee84Perform the upload
In this example we are using cURL:
curl -X PUT -T ./example.txt \
-H "Content-Type: text/plain" \
"https://s3.eu-central.r-cdn.com/5682/example.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=FSCIDQAGGF8EDQFFBJOZI%2F20250930%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250930T093646Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Signature=c8097d1e2bb2aea5acfeacf63826fc20a68897d4322768e39ae548cbbf6dee84"Verify the upload
# Virtual-hosted style request (default)
curl -I "https://5682.s3.eu-central.r-cdn.com/example.txt"
# Path-style request
curl -I "https://cXXXzYYY.r-cdn.com/example.txt"