Store uploads on S3-compatible storage
Problem
You want user uploads on S3 / R2 / B2 instead of the local disk.
The Storage trait abstracts the backend. Swap LocalStorage for S3Storage (hand-rolled SigV4 — no aws-sdk dependency) and the upload code is unchanged.
let storage = S3Storage::new(S3Config {
bucket: "uploads".into(),
region: "auto".into(),
endpoint: Some("https://<acct>.r2.cloudflarestorage.com".into()),
..Default::default()
});
let key = storage.put("avatars/42.png", bytes, "image/png").await?;
let url = storage.public_url(&key);
See also: the Media model for first-class file references