S3MediaStorage uploads media to an S3 bucket and keeps only a MediaReference in the database. It also supports MinIO and other S3-compatible services through endpoint_url.
Usage
Install the required packages:AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, or pass the credentials directly. Pass region explicitly: left unset, boto3 falls back to AWS_DEFAULT_REGION or ~/.aws/config, and it does not read AWS_REGION.
media_storage_s3.py
Async
AsyncS3MediaStorage takes the same parameters and uses aioboto3.
URLs
get_url returns a presigned URL that expires after presigned_url_expiry seconds. A presigned URL is never written to the database, since it would expire and it carries credentials, so a fresh one is signed on each read. Above the SigV4 maximum of seven days, no URL is signed and readers stream the bytes instead.
Set acl="public-read" to return the unsigned object URL instead. That URL does not expire, so it is stored on the reference. A bucket with ACLs disabled, the default for new buckets, rejects the argument with a ValueError.
S3-compatible Services
Pointendpoint_url at the service and set region to match its own site region.
A presigned URL carries the region in its signature. A service whose region differs from the one configured here rejects the URL.
Params
See the full example here.