3

I want to publish the Media item as soon as it is uploaded in the Media library. I was looking at different pipelines to resolve this but couldn't figure out which one is the ideal one to do so.

As it is a media item item saved event is not triggered.

2 Answers 2

3

You can do it with uiUpload processor:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <processors>
            <uiUpload>
                <processor mode="on" type="{YourSolutionName.ProjectName.PublishMediaItem}, AssemblyNameSpace{YourSolutionName.ProjectName}" patch:after="processor[@type='Sitecore.Pipelines.Upload.Done, Sitecore.Kernel']" />
            </uiUpload>
        </processors>
</configuration>

Your class will be:

namespace YourSolutionName.ProjectName
{
    public class PublishMediaItem: UploadProcessor
    {
        public void Process(UploadArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            foreach (string index in args.Files)
            {
                HttpPostedFile file = args.Files[index];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    //write your publish code here
                    args.AbortPipeline();
                    break;
                }
            }
        }
    }
}
1

You can add your custom processor into the pipeline or replace the existing processor with a custom one. you can change the standard Sitecore behavior in order to enhance or change the way they work.

The file uploading process is defined by pipeline <uiUpload> in the web.config file. Please have a look at the <processors> section in this file:

 <uiUpload>

      <processor mode="on" type="Sitecore.Pipelines.Upload.ResolveFolder, Sitecore.Kernel" />

      <processor mode="on" type="Sitecore.Pipelines.Upload.Save, Sitecore.Kernel" />

      <processor mode="on" type="Sitecore.Pipelines.Upload.Unzip, Sitecore.Kernel" />

      <processor mode="on" type="Sitecore.Pipelines.Upload.Done, Sitecore.Kernel" />

</uiUpload> 

Reference: Customizing the Upload Process

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.