Class: MediaResource
Media resource for interacting with the TentoCMS Media API
Methods
getById()
getById(id, options?): Promise<Media>;
Get media metadata by ID
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The media ID |
options? | PreviewOption | - |
Returns
Promise<Media>
The media object with metadata
Throws
If the media is not found
Example
const media = await client.media.getById('abc123')
console.log(media.filename)
console.log(media.width, media.height)
getImageUrl()
getImageUrl(id, options?): string;
Get a transformed image URL
This method returns a URL string and does not make an HTTP request. The actual image transformation happens when the URL is accessed.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The media ID |
options? | MediaTransformOptions | Transform options (width, height, fit, quality, etc.) |
Returns
string
URL string for the transformed image
Example
// Get a 400x300 thumbnail
const thumbnailUrl = client.media.getImageUrl('abc123', {
width: 400,
height: 300,
fit: 'cover',
quality: 80
})
// Use in an img tag
<img src={thumbnailUrl} alt="Thumbnail" />
getSrcSet()
getSrcSet(
id,
widths?,
options?): string;
Generate a srcset string for responsive images
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The media ID |
widths | number | Array of widths to generate (default: 640, 768, 1024, 1280, 1536) |
options? | Omit<MediaTransformOptions, "width"> | Additional transform options (fit, quality, format, etc.) |
Returns
string
srcset string for use in img tag
Example
const srcset = client.media.getSrcSet('abc123', [400, 800, 1200])
// Returns: "https://api.../media/abc123?width=400 400w, ..."
<img
src={client.media.getImageUrl('abc123', { width: 800 })}
srcSet={srcset}
sizes="(max-width: 768px) 100vw, 50vw"
alt="Responsive image"
/>
getThumbnailUrl()
getThumbnailUrl(id): string;
Get a thumbnail URL (400x400, cover fit, quality 80)
This is a convenience method for common thumbnail use cases.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The media ID |
Returns
string
URL string for the thumbnail
Example
const thumbnail = client.media.getThumbnailUrl('abc123')
transformUrl()
transformUrl(url, options?): string;
Append image transform params to an existing media URL string.
Unlike getImageUrl(id, …), this works on the _url of a TentoMedia object resolved
inline in page/collection content — which has no media id. Returns a URL string and makes
no HTTP request; safely appends even if the URL already has a query string.
Parameters
| Parameter | Type |
|---|---|
url | string |
options? | MediaTransformOptions |
Returns
string
Example
const src = client.media.transformUrl(page.fields.hero._url, { width: 800, fit: 'cover', format: 'webp' })

