Metadata setting structure
The following code snippet shows an example of the ImportMetadataConfiguration setting. This JSON configuration maps metadata extracted from uploaded files (such as file size, file name, and image width from various sources) to specific asset properties and relations in Sitecore Content Hub. It defines how metadata should be transferred into the MainFile property and the MasterFile relation, including optional conversions like file size formatting.
{
"from": {
"extension": "extension",
"filesize": {
"file": "metadata",
"path": ["$['File:FileSize']"]
},
"filename": {
"file": "metadata",
"path": ["$['File:FileName']"]
},
"width": {
"file": "metadata",
"path": [
"$['Composite:ImageWidth']",
"$['File:ImageWidth']",
"$['EXIF:ImageWidth']",
"$['QuickTime:ImageWidth']",
"$['MPEG:ImageWidth']",
"$['PNG:ImageWidth']",
"$['GIF:ImageWidth']",
"$['Photoshop:ImageWidth']",
"$['RIFF:ImageWidth']",
"$['ASF:ImageWidth']"
]
}
},
"to": {
"properties": {
"MainFile": {
"bag": "properties",
"properties": {
"extension": "extension",
"filesize": {
"value": "filesize",
"conversion": "FileSize"
},
"filesizebytes": "filesize",
"filename": "filename",
"width": "width"
}
}
},
"related": [
{
"relation": "MasterFile",
"role": "Child",
"properties": {
"FileSize": {
"value": "filesize",
"conversion": "FileSize"
},
"FileProperties": {
"bag": "properties",
"properties": {
"extension": "extension",
"width": "width"
}
}
}
}
]
}
}
The ImportMetadataConfiguration JSON configuration contains two sections:
-
from- metadata to extract from the uploaded file. -
to- set properties where the metadata is to be mapped.
The from section
The from section of the example contains three types of metadata property declarations. The following table explains them:
|
|
Description |
|---|---|
|
RequestResponse |
Note Lack of |
|
RequestResponse |
Note The |
|
RequestResponse |
Note When the |
The to section
The to section maps metadata properties defined in the from section to the asset properties.
When you upload a file, it is associated with an asset entity using the MasterFile relation. The to section in the metadata configuration starts with the file entity properties and continues with the asset entity properties using the related attribute.
The following diagram illustrates the structure of the to section:
The to section contains two parts, properties and related.
Properties mapping
properties is a list of mappings between the from section and the file entity properties. A mapping can be complex, containing sub-properties organized in bags; or simple, containing simple single-valued properties.
A complex mapping is a property that references a member of the entity definition, such as MainFile. It includes the following properties:
-
bag- name of the bag in which the properties are stored, such asproperties. -
properties- list of simple properties to be stored in the bag.
A simple mapping is a property that references a member of the entity definition, such as filesize. It includes the following properties:
-
value- value assigned to the property. For example,filesizethat references a property of thefromsection. -
conversion- conversion to apply on the value. For example,FileSize.
Both value and conversion are optional, so you can provide a simple key-value mapping instead, such as width:width.
Related mapping
related is an array of mappings between the from section and the properties of related entities such as Asset.
A related mapping is a property that describes the relation to a related entity, such as MasterFile. It includes the following properties:
-
role- role of the file entity in the relation. For example, in theMasterFilerelation, File is a child of Asset. Valid values areparentorchild. -
properties- an array of complex or simple property mappings to the related entity.
Conversion logic
Metadata configuration supports the following values for the conversion property:
-
Duration- Rounds the duration value with a factor of 1000. -
FileSize- Rounds the file size using two decimal places and a factor of 0.000001. -
ArrayToString- Concatenates the elements of the array to create a single, comma-separated string.