Skip to content

Media

A media field on an entry stores a media item’s id.

const imageUrl = cms.media.url({ id: post.data.featuredImage as string });
const meta = await cms.media.get({ id: post.data.featuredImage as string });

media.url only builds a URL ({api}/api/v1/public/media/{id}/file) and makes no request. media.get resolves { altText, contentType, width, height }, or null if the item does not exist.

<img src={imageUrl} alt={meta?.altText ?? post.data.title} width={meta?.width} height={meta?.height} />

To fetch a curated set, use a media folder’s slug:

const hero = await cms.media.byFolder({ slug: 'home-page-hero' });

The file route is unauthenticated and edge cached for a year. Files are immutable, and deleting one invalidates its cache entry. Through the proxy, createKenresoftClient({ url: '/cms' }) builds /cms/api/v1/public/media/{id}/file, which the allow-list permits.

See Media architecture.