Asset Parameter Utilities
Asset parameters store references to images, videos, and other media files managed through Uniform's asset library or connected DAM integrations.
Using flattenValues#
Use flattenValues from @uniformdev/canvas to extract asset data from ComponentParameter<AssetParamValue> values. This utility normalizes the parameter structure into a usable format.
flattenValues options#
| Option | Type | Default | Description |
|---|---|---|---|
toSingle | boolean | false | When true, returns a single asset object instead of an array. Use for parameters that contain exactly one asset. |
Returned asset object#
Each flattened asset object contains:
| Property | Type | Description |
|---|---|---|
url | string | The URL of the asset |
width | number | Width in pixels (images) |
height | number | Height in pixels (images) |
fields | object | Additional metadata fields (e.g., alt, title, description) |
mediaType | string | MIME type of the asset |
Accessing asset metadata fields#
Asset metadata (like alt text) is stored in the fields property:
Using with Next.js Image#
warning
Always use flattenValues from @uniformdev/canvas for asset parameters. Do not create custom utility functions for extracting asset data.
Use an AI coding assistant
The uniform-assets agent skill teaches coding assistants such as Claude Code, Codex, Cursor, and Copilot how to define asset parameters, render images with imageFrom, read asset fields, and seed or migrate asset values. To install it, see Uniform agent skills.