Rendering assets
This page describes the shape of the asset parameter value returned by the Uniform APIs and the SDK utilities you can use to render assets in your frontend. For the editor-facing flow, see the asset parameter. For configuration options when defining the parameter on a component, see parameters for components.
Asset properties#
The asset parameter provides a composition with a set of properties about an asset, reducing or eliminating the need to model them as separate component parameters. The data within the asset parameter is returned as an array, even if the array only contains one item.
API responses include these fields:
| Parameter | Description | Allowed values | Required |
|---|---|---|---|
| type | Broad category of the asset | image, video, audio, other | Yes |
| _source | Internal field indicating the source of the image. It could be an integration ID, a data resource name, or a custom string | uniform-assets, <string> | No |
| _id | Random, persisted UUID assigned to the asset parameter array item to assist with frontend rendering (for example, as a value for the React key property). This is not the ID of the asset, which is instead found in the fields.id property. | <UUID string> | Yes |
| fields.id | ID of the asset | { type: 'text', value: '<UUID string>' } | No |
| fields.url | URL pointing to the binary file | { type: 'text', value: '<URL>' } | Yes |
| fields.title | Title of the asset | { type: 'text', value: '<STRING>' } | No |
| fields.description | Description of the asset | { type: 'text', value: '<STRING>' } | No |
| fields.mediaType | Media (mime) type of the asset | { type: 'text', value: '<STRING>' } | No |
| fields.width | Width of the asset (in case of an image) | { type: 'number', value: <NUMBER> } | No |
| fields.height | Height of the asset (in case of an image) | { type: 'number', value: <NUMBER> } | No |
| fields.focalPoint | Focal point of the asset (in case of an image) | { type: 'focalPoint', value: { x: <NUMBER>, y: <NUMBER> } } | No |
In the context of a composition, the response from the API would be structured like this:
Frontend rendering#
JavaScript#
Asset utilities are provided by the Uniform SDK to streamline the process of rendering assets in your application.
For interacting with the Image Delivery API, an imageFrom utility is available, exported from the @uniformdev/assets package. The utility assists with the following:
- Extracting a URL from an asset parameter
- Constructing a URL compatible with the Image Delivery API transformations, for assets sourced from the Uniform Asset Library
tip
The imageFrom utility will automatically respect the focal point of the asset passed to it if present, you do not need to manually pass it in.
info
Calls to .transform() will be ignored for non-image assets, and any assets not sourced from the Uniform Asset Library. In those cases, the original URL will always be returned.
TypeScript types#
The assets SDK (available under @uniformdev/assets) exports types that can be useful when rendering assets in your application.
Next.js#
When rendering images coming from the Uniform Asset Library, you will need to follow a few steps:
- Enable images coming from the Uniform CDN
In your next.config.ts file, add img.uniform.global as an allowed remote pattern:
- Use the
imageFromutility documented above in combination with theImagecomponent:
- For background images you can use the
Imagecomponent together with thefillproperty, like so: