Sitecore Best Practices Video Blog
  • TRAINING
  • BEST PRACTICES
  • PROJECTS
  • BLOG
  • WHITE PAPERS
  • ABOUT
  • CONTACT

Viewing Asset XMP Data in Sitecore Content Hub

Vasiliy Fomichev

In Content Hub, DAM, Uncategorized Posted March 18, 2020

In this post, we will cover extracting and viewing digital asset information embedded into files using the Extensible Metadata Platform (XMP) standard. We’ll take a look at the steps needed to extract the information and view it as part of the digital assets’ detail view. The implementation requires elevated access rights to be able to create a custom script and extend asset schema, and optionally update asset display view. There is no shortcut or TL;DR here; however, I’ll keep it focused and concise.

 

What is XMP?

XMP is an industry standard for storing digital asset descriptive and contextual information developed by Adobe. To get more detail about the format, please reference the Adobe’s XMP information page. The XMP metadata is especially important in rights management, asset tagging, and taxonomies.

 

Updating Asset Schema

The first step is to update asset schema to add fields for displaying the XMP information. The number of fields and their types will depend on the amount of XMP information that needs to be extracted. In this example, we’ll focus on adding one field, as the same approach can be used for adding more if needed.

To update asset schema, navigate to Manage > Schema and click on M.Asset. In the M.Asset view, select the section you’d like to add the new field to, or create a new one, then click “NEW MEMBER” button to start adding a new property to the M.Asset entity.

Sitecore Content Hub Asset Schema

Since the information that we are importing here is simple text and not a complex object, we will pick the Property option in the new member type prompt, then String for the format and click NEXT. The following window allows us to configure additional information about the field. For this example, we will leave the defaults in place and only update the Name and Label fields. The label is optional, but it’s one of my rules to have user-friendly labels, especially since its best to keep names developer-friendly for API access. We’ll set the name to “CameraBrand” and label – “Camera Brand.”

Sitecore Content Hub Schema Field Editor

Click SAVE to add the property and Publish for the change to become effective.

NOTE: Once added to the section that’s already displayed on the asset detail page, the property will automatically be visible on asset detail pages. In cases when adding to a new property group or a section that’s not displayed, navigate to Manage > Pages and search for Asset Detail Page. After clicking on the page, you’ll be presented with a component-based representation of the asset detail page template. Here you may choose to either create a new section to display the metadata or add it to an existing one.

Create a Script to Extract XMP Information in Content Hub

Navigate to Manage > Scripts and click NEW SCRIPT. In the prompt specify the name, make sure to set the type to “Metadata processing”, and click SAVE. To start updating the newly created script, click the “…” on the right of the script line item and click Edit. Once in the editing view, copy and paste the following code –

using System.Linq;
var masterFileRelation = await Context.File.GetRelationAsync("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 cameraBrand = await Context.Asset.GetPropertyAsync("CameraBrand");
if(Context.MetadataProperties.ContainsKey("make")){
   cameraBrand.SetValue(Context.MetadataProperties["make"]?.ToString());
}

await MClient.Entities.SaveAsync(Context.Asset);
MClient.Logger.Info($"XMP metadata processed for asset ID {Context.Asset.Id}."); 

 

Click BUILD and wait for the system to build the script; once successfully completed, click PUBLISH. Once published, click the back arrow in the top-left corner to go back to the script listing view, or navigate to Manage > Scripts and make sure that the script is enabled by ensuring it has a green check ticked on the line-item. That’s it!

Sitecore Content Hub Script View PageTo test the script, try uploading the following small image that has XMP data embedded in it, then checking the detail page (note that by default, empty fields are hidden on the asset detail view).

Like this:

Like Loading...

Related

Summary
Viewing Asset XMP Data in Sitecore Content Hub
Article Name
Viewing Asset XMP Data in Sitecore Content Hub
Description
Adobe's standard for storing descriptive and contextual digital asset information is natively supported in Sitecore Content Hub. This article describes how to enable it in asset detail view.
Author
Vasiliy Fomichev
Content HubDAMmetadatascriptsitecorexmp
Commerce, Infrastructure, LASUG

Sitecore Los Angeles Virtual User Group: Sitecore Commerce and SPE with SXA and Docker

Sitecore Best Practices Video Blog
© Copyright Vasiliy Fomichev. All rights reserved. Privacy Policy
This website uses cookies to improve your experience. You may configure cookie settings here. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT
%d