getAssetUrl
function getAssetUrl(asset, preset): string;Defined in: packages/asset-client/src/index.ts:290
Build the public CDN URL for a specific variant of an asset. The variant
may not actually exist (regenerate may not have run, or video has no
aiproxy); call hasPreset() first or expect a 404.
Pass the asset’s mime (present on the full AssetDTO) so the original
preset resolves to the correct extension; without it the original falls back
to the "bin" sentinel.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
asset |
Pick<AssetDTO, "sha"> & { mime?: string; } |
preset |
VariantPreset |
Returns
Section titled “Returns”string
Examples
Section titled “Examples”Video — the tenant segment is base36, so let this build the path
import { getAssetUrl, setTenantId } from "@aquienpz/asset-client";
setTenantId(12); // 12 → "c"; a decimal "/12/v/" 404sgetAssetUrl({ sha }, "video"); // → https://8ok.uk/c/v/<sha16>-v.mp4getAssetUrl({ sha }, "poster"); // → https://8ok.uk/c/v/<sha16>-p.webpThe `original`, which needs the mime — and still deserves a HEAD
getAssetUrl({ sha }, "original"); // → …-o.bin ❌ 404, alwaysgetAssetUrl({ sha, mime }, "original"); // → …-o.webp ✓
// ⚠️ The stored extension comes from the UPLOADED FILENAME, not the mime:// "image/jpeg" builds "-o.jpeg" while a camera's ".jpg" was stored as "-o.jpg".// When the URL must be right, verify it:const res = await fetch(url, { method: "HEAD" });Check before you link
import { getAssetUrl, hasPreset } from "@aquienpz/asset-client";const url = hasPreset(asset, "thumb") ? getAssetUrl(asset, "thumb") : null;