sitecoresitecore8sitecore-mvc

How do you create a Sitecore pipeline processor that runs when a new item is upload to the Media Library


I would like to build a Sitecore pipeline processor that would grab the ID of a media item when it is uploaded and save that ID to an existing custom database that is used by a third-party application.

I have been unable to locate any How-to or examples on how to do this?

I am using Sitecore 8.0 Update 5 and an MVC structure for my code.


Solution

  • You can check in the uiUpload pipeline, but that will not fire for programatically created items, i.e. it will only fire when a user uploads an item via the CMS interface.

    Create a new processor class:

    public class ExternalSystemProcessor
    {
        public void Process(UploadArgs args)
        {
            foreach (Item file in args.UploadedItems.Where(file => file.Paths.IsMediaItem))
            {
                // Custom code here
                SaveToExternalSystem(file.ID);
            }
        }
    }
    

    And then patch the in after the default save processor:

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
      <sitecore>
        <processors>
          <uiUpload>
            <processor type="MyProject.Custom.Pipelines.ExternalSystemProcessor, MyProject.Custom" mode="on"
                       patch:after="*[@type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" />
          </uiUpload>
        </processors>
      </sitecore>
    </configuration>