Assets in Uniform
The asset parameter and asset field each provide a seamless interface for adding media into a composition or content entry. The parameter can be configured to support multiple asset selection. Each asset may be from a different source. All assets have standard fields where you can add context-specific content, or connect to an external data source like a CMS or e-commerce system.
tip
For details on adding the asset parameter to a component, refer to the parameter guide. To add assets to a content type, refer to the field guide.
Connect to an asset#
There are three ways to connect to an asset:
- Through an asset source
- From an existing data resource
- Via a custom URL
Asset sources#
Choose assets from the built-in Uniform Asset Library, or connect to your existing DAM system or other asset sources by using integrations.
Data resources#
You can select assets from any existing data resource for entries. This is useful to select an image from the current product entry used to assemble a product detail page in Canvas.
Custom URL#
Selecting this option provides a way to create an inline link to an image URL hosted elsewhere.
Select an asset#
How to select an asset depends on the source of the asset. Once added, a preview of the image is shown and the current asset count updates.
info
The ability to select more than one asset depends on how you configure the parameter. You may need to remove an asset before being able to add a new one.
Manage your selection#
Once you have added an image to the asset parameter in a composition, you can:
- Reorder assets: You can reorder assets by dragging and dropping them within the property panel of Canvas. This will change the order of items in the array in which they're delivered through the APIs.
- Edit asset properties: If you click on an asset in the property panel, it will open in it in a modal. If the asset is sourced from the Uniform Asset Library, you can override the asset properties by selecting the Override for this parameter option in the menu.
- Remove: If you click on an item in the property panel, it will open in it in a modal. Clicking "remove from selection" will remove the asset from the selection. The uploaded file and asset record (if applicable) won't be deleted. However, any customization of any properties will be lost.
info
When you edit an asset property from within a composition, you will override the information coming from the asset. Those changes aren't written back to the asset's source, like the asset library. The changes remain specific to the usage within the composition. If you edit the asset at the source, such as in the asset library, those changes will be present wherever the asset is used throughout the project.
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 assist 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
imageFrom
utility documented above in combination with theImage
component:
- For background images you can use the
Image
component together with thefill
property, like so: