In my recent Sitecore Content Hub project, I ran into an issue where the asset file names were not preserved when imported via excel template. The issue is so specific to public URLs and for some reason, Content Hub ignores or rather overrides the file name that is specified in the imported excel and takes the file name from the public URL. Content Hub preserves the file name for local URLs (assets from local hard drive).
Here's a sample excel import template with couple of rows to import:
As you may notice, you can see the FileName for both the assets differs from the file name in the public URL specified (under File column).
To overcome this, I need to create a new M.Asset schema property called OriginalFileName (it could be anything that you want it to be) and store the original file name into this new property in the Pre-Commit script and restore this value into the FileName property in the Metadata Processing script as described below.
Save and publish the changes to the M.Asset schema
After I imported the excel into Sitecore Content Hub and looked at the details of one of the assets, it overwrote the file name (oatmeal-pro.jpg mentioned in the excel) with oatmeal.jpg (file name from the public URL) as in the screenshot below.
To overcome this, I need to create a new M.Asset schema property called OriginalFileName (it could be anything that you want it to be) and store the original file name into this new property in the Pre-Commit script and restore this value into the FileName property in the Metadata Processing script as described below.
M.Asset schema new property
Save and publish the changes to the M.Asset schema
Pre-Commit Script for storing the file name into the OriginalFilename property
Ensure the trigger that you create is set to "In Process" so you can call the action script in "Pre commit" phase as shown below.
Metadata Processing Script for restoring the original file name
After this, when you import assets via excel, it will restore the original file name mentioned in the excel document.
One thing to note is that it will take few seconds to restore the original file name, and it is done after the fetch job fetched the file from the public URL.
Hope you found this blog post useful!
Comments
Post a Comment