getAssetUrl
function getAssetUrl(asset, preset): string;Defined in: packages/asset-client/dist/index.d.ts:1099
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.
For the original preset, pass the whole AssetDTO — it carries variants
and oext, either of which gives the EXACT stored key. mime alone is only a
guess (the server keys the original off the uploaded filename), and with
nothing at all the original falls back to the "bin" sentinel, which 404s.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
asset |
Pick<AssetDTO, "sha"> & OriginalHints & VisibilityHint & Partial<Pick<AssetDTO, "presets">> |
⭐ presets ESTÁ EN EL TIPO PORQUE LA FUNCIÓN LO LEE. transformFallbackFor decide con este campo si devolver la clave de variante o caer a /t/…width=N/. Sin él en la firma, el tipo PROHIBÍA el campo que la implementación consulta: pasarlo era un error de compilación, y no pasarlo daba …-x.webp → 404 en silencio. Medido 2026-08-25 sobre un asset con presets: "lmoqs": sin presets → /f/v/presets → /t/format=webp,width=3840/ |
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 "@nitida/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` — pass the DTO, not just the sha
const asset = await aq.assets.get(id);
getAssetUrl({ sha }, "original"); // → …-o.bin ❌ 404, alwaysgetAssetUrl({ sha, mime }, "original"); // → a guess from the mime tablegetAssetUrl(asset, "original"); // ✓ the stored key, verbatimCheck before you link
import { getAssetUrl, hasPreset } from "@nitida/asset-client";const url = hasPreset(asset, "thumb") ? getAssetUrl(asset, "thumb") : null;