We will extend the asset schema to automatically set metadata from EXIF data recorded by camera manufacturers. This section provides the procedure and related information for importing and using this metadata.
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F6sgy7Ovuz4tlgh2cEKEU2e%2Fd185316d302ee55b4d84363b43bad23a%2Fbrandcameraupdate.png&w=3840&q=75)
What is XMP data?
In order to support XMP (Extensible Metadata Platform), digital asset management tools must be able to provide metadata about digital assets. Sitecore Content Hub provides standard metadata and can be extended as needed.
The following data will be displayed as properties of the file after standard import.
![fileproperties.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FaiWbpiy7WbBLSirQFRpMK%2F39d9a3094aea27bde9077112ab95b9cf%2Ffileproperties.png&w=3840&q=75)
This scenario
One of the data contained in the photo is the name of the camera manufacturer. The following is a procedure for extending this into the schema and setting it up automatically.
- Camera brand
Sample images to be used as a test were downloaded from the following site
Schema Extension
The first step is to extend the schema to create an entry for the camera brand.
- Open the Schema in the admin panel
- Select M.Asset as the schema type
- Select the group in the Overview, then click New Member.
- As for the item, this time select Properties and go next.
- Select String for property type and go to next
- Enter the schema entry (in this case CameraBrand )
- After saving, publish the schema
This results in an extended schema.
![schemacamerabrand.gif](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FYYti4Cpl6bMSMmg48ppAw%2F842e59ff3203d09142422580d6d34180%2Fschemacamerabrand.gif&w=3840&q=75)
Creating Scripts
Sample scripts for processing metadata can be found at the following sites
First, paste the code as is. (Detailed explanation of the process can be found on the page, so we will only introduce the process here.)
using System.Linq;
var masterFileRelation = await Context.File.GetRelationAsync<IChildToManyParentsRelation>("MasterFile");
if (!masterFileRelation.Parents.Any() || !masterFileRelation.Parents.Contains(Context.Asset.Id.Value))
{
return;
}
string ToCsvValue(object source)
{
var str = source.ToString();
if (str.Contains(","))
{
return "\"" + str + "\"";
}
return str;
}
var headers = string.Join(", ", Context.MetadataProperties.Keys.Select(ToCsvValue));
var values = string.Join(", ", Context.MetadataProperties.Values.Select(ToCsvValue));
var metadataProp = await Context.Asset.GetPropertyAsync<ICultureInsensitiveProperty>("Metadata");
metadataProp.SetValue(headers + "\n" + values);
await MClient.Entities.SaveAsync(Context.Asset);
This script takes metadata information as a CSV and outputs it to the Metadata property of the asset. For this part, we will process it as JSON data and use JToken. Then, in the JSON data, the camera brand is listed as _make_, so add a definition.
using System.Linq;
using Newtonsoft.Json.Linq;
string cameraBrandKey = "make";
MClient.Logger.Info("Metadata Mapping starts.");
var masterFileRelation = await Context.File.GetRelationAsync<IChildToManyParentsRelation>("MasterFile");
if (!masterFileRelation.Parents.Any() || !masterFileRelation.Parents.Contains(Context.Asset.Id.Value))
{
return;
}
JToken cameraBrand;
if(Context.MetadataProperties.TryGetValue(cameraBrandKey, out cameraBrand))
{
Context.Asset.SetPropertyValue("CameraBrand", cameraBrand.ToString());
}
else
{
MClient.Logger.Info($"Could not find a value for {cameraBrandKey}");
Context.Asset.SetPropertyValue("CameraBrand", $"{cameraBrandKey} not found");
}
await MClient.Entities.SaveAsync(Context.Asset);
If you are adding other keys, you can increase the number of items by creating multiple parts of the JToken description.
Register Scripts
When registering a script, you must select the type of metadata processing, as this time it will be a script to be executed in media processing.
![brandname.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FL2G9TX3bLH6bURszhBPzn%2Fa2bcff3f5e2d93976dd2a8f798a89f12%2Fbrandname.png&w=3840&q=75)
The next step is to register, build, and activate the script.
![registscript.gif](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F6vsr2QcFY7ac2kmcrqowep%2Fe35ecb71773b454e5cbabf709181b660%2Fregistscript.gif&w=3840&q=75)
Once registration is complete, the script should be activated.
Testing and confirmation of results
When the script is enabled, the setup is complete. The registered script is executed at the time of media processing when a file is uploaded. Therefore, as a test, when a file is uploaded, data is automatically set from the _make_ item to the item extended as the schema.
![brandcameraupdate.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F6sgy7Ovuz4tlgh2cEKEU2e%2Fd185316d302ee55b4d84363b43bad23a%2Fbrandcameraupdate.png&w=3840&q=75)
Summary
As described above, data held as file properties can be expanded into a schema, and faceted settings, refinements, etc. can be made using the data expanded into the schema. The schema will be expanded and scripts will be registered according to the actual operation.