pub fn public_url(ctx: &Ctx, key: &str) -> Result<String>Expand description
The permanent public URL of key in a public bucket: <STORAGE_PUBLIC_URL>/<key> (Active Storage’s public: true).
Requires public access on the bucket (an r2.dev URL, rate-limited and
meant for development, or a custom domain) and the
STORAGE_PUBLIC_URL variable.
Every object of the bucket is then public forever to whoever has its
key, with no authorization and no expiry: use it for avatars and
product images, never for private documents. Pure string building: no
R2 operation; downloads are class B operations on R2’s side.
§Errors
Error::Internal (500) when
STORAGE_PUBLIC_URL is not set (the message says how).
§Examples
use ocre::{Ctx, Result, storage::{self, Attachment}};
fn avatar_src(ctx: &Ctx, avatar: &Attachment) -> Result<String> {
storage::public_url(ctx, &avatar.key) // https://files.example.com/users/avatar/2u1Vd0zJ8sQqS6rJq0rVmA
}