How to setup a Media Processing Flow in Sitecore Content Hub

Although the Sitecore Content Hub Documentation is good and there is an elearning module for Sitecore  Content Hub, there are a few areas everybody might interpret differently and have issues as a result. For instance, I was trying to setup an image processing flow in the Sitecore Content Hub, once  I setup the flow, it was a bit difficult for me to figure out where to find the results! It  required me to  do some to and fro between pages. So, this blog is for people like me who are struggling to find things after they do! 

In this blog, I'm going to setup a media processing flow first and see if what I setup is reflected in the asset rendition. Note that I'm using media and image interchangeably here although image is a subset of media!

Before getting started, here is my representation of the media processing flow:


Definitions:

Job processes multiple sets

Set has a workflow

Workflow has tasks

Asset is processed as input by a workflow to  produce multiple renditions as output

Scenario: For all GIF images uploaded, automatically create a rendition that will be 50px by 50px irrespective of the image aspect ratio

Again, the elearning module for Sitecore  Content Hub is good at detailing how to setup a workflow:


Based on the same, you shouldn't have issues adding a set and then a flow within a set. Beware of the naming convention here, a flow is created within a set!

I've just created a set in my Sandbox -


Now, the navigation from here is a bit tricky, you won't see an explicit edit button. There are two options on the row:

A. if you hover the row, you will  find the Edit tool-tip so, clicking the row will open the following window:


B. On the other hand, if you click the cogwheel in the row, can edit just the flow settings:


Since I want to setup a media processing workflow, I'm going with option A and click the + sign in the middle of the window and, I get this option to add a new task:


To start with, I desire to Convert an image so, click Convert an image option appearing to the right on clicking the task and I get this dialog:


This is how I setup the flow parameters targeting gif file type:


So, irrespective of the dimensions of the image, I want to convert it to 50px by 50px and ignore aspect ratio for my case.

Next, the most important tab is the Outputs tab that is useful in specifying the name of the rendition that must be generated by enabling the Store output switch displayed here:


Then, click on the New link to setup other details of the rendition:


I enabled watermark to see what happens!

Once I click the save task and exit the window, then comeback to see that there is an edit link now and it means that everything is saved fine:


Once you save and close, there is an option to publish, click the publish button. Next, let us navigate to the assets page and refresh renditions in order to fire the workflow on existing files, this option is available when you do a mass-edit of the assets:


Click the submit button:


Next, click one of  the assets, go to the asset details page and the new rendition must be available in the last page:


Since everything runs as a job, you might not see the rendition populated right away on the page, I first ensure that I'm on the correct asset type then refresh the asset details page or better, practise some patience!

Note that the flow is only triggered for gif file type since that is what we set up the flow for! You can check other file types to ensure the rendition with the same name is not created. For gif files, you can see that the file is resized as per the task we setup! One thing I couldn't find is, the water mark but I would park it for now since the image is so small to figure out the presence of a watermark!

If you add a new asset of type gif and publish the asset, a 50px by 50px rendition will be automatically created and displayed under the list of renditions in the asset' details page.

There are also other flows getting triggered by default for image thumbnails and they are setup here:



Click the above row to open this window, click through each task to check what it does:



Pick the rendition and save to local file system using a .net core console app -

**************************************************

static async Task DownloadMethod(IWebMClient client)
        {
            var asset = await client.Entities.GetAsync(30767);//this asset id must be present and picked from asset details  page
           
            if (asset != null)
            {
                var original = asset.GetRendition("convertgif");
                var rendition = original.Items.FirstOrDefault();

                if (rendition != null)
                {
                    var filename = asset.GetPropertyValue<string>(Constants.Asset.FileName);
                    var directory = @".";
                    var filepath = Path.Combine(directory, filename);
                    await rendition.DownloadAsync(filepath);
                }
            }

        }
        static void Main(string[] args)
        {
            // Your Sitecore Content Hub endpoint to connect to
            Uri endpoint = new Uri("https://mysandbox.stylelabs.io/");

            // Enter your credentials here
            OAuthPasswordGrant oauth = new OAuthPasswordGrant
            {
                ClientId = "localsitecore",
                ClientSecret = "localsecret",
                UserName = "NewUser",
                Password = "send reset password link to be sure you are passing correct pwd"
            };

            // Create the Web SDK client
            IWebMClient client = MClientFactory.CreateMClient(endpoint, oauth);
            DownloadMethod(client).Wait();
        }




*************************************************

Have fun playing with media processing flow!

Reference: https://docs.stylelabs.com/contenthub/4.0.x/content/integrations/sdk-common-documentation/entity/renditions.html

Comments

Popular Posts