Python SDK - Storage#
S3-compatible object storage: buckets, objects, folders and presigned URLs.
Buckets#
bucket = db.storage.create_bucket(
name="Avatars",
slug="avatars",
is_public=True,
file_size_limit=5_000_000, # optional, bytes
allowed_mime_types=["image/png", "image/jpeg"], # optional
)
bucket.data # {"id": "...", "slug": "avatars", ...}
db.storage.list_buckets()
db.storage.get_bucket(bucket_id)
db.storage.delete_bucket(bucket_id)
PythonObjects#
db.storage.list_objects(bucket_id)
db.storage.create_folder(bucket_id, "user-uploads")
db.storage.delete_object(object_id)
PythonUpload#
Get a presigned URL, then PUT the file bytes to it:
import urllib.request
upload = db.storage.signed_upload_url(
bucket_id=bucket_id,
object_name="user-1.png",
content_length=20480, # optional
)
with open("user-1.png", "rb") as f:
req = urllib.request.Request(upload.data["url"], data=f.read(), method="PUT")
urllib.request.urlopen(req)
PythonDownload#
download = db.storage.signed_download_url(object_id)
# Public URL (no auth, public buckets only)
public = db.storage.public_url(bucket_id, object_id)
PythonNext: Environment variables.