Skip to main content
GCSMediaStorage uploads media to a Google Cloud Storage bucket and keeps only a MediaReference in the database.

Usage

Install the required packages:
Authenticate with gcloud auth application-default login, or pass a service-account JSON through credentials_path.
media_storage_gcs.py

Async

AsyncGCSMediaStorage takes the same parameters. google-cloud-storage has no native async API, so each call runs in a worker thread.

URLs

Signing a URL needs a credential that carries a private key. Pass credentials_path, or point GOOGLE_APPLICATION_CREDENTIALS at a service-account JSON.
Application-default credentials from gcloud auth or a VM carry only a token. With those, get_url returns None and AgentOS streams the bytes through its media route. public=True returns the public object URL instead of a signed one. It grants no access by itself: under uniform bucket-level access, the default for new buckets, the bucket must already grant roles/storage.objectViewer to allUsers or the URL answers 403.

Params

See the full example here.