You can do this by creating a custom processor for attachFile
pipeline. Create a patch file like below -
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<processors>
<attachFile>
//Add the patch:before type where you want to add your procesor
<processor type="xyz.foundation.className,xyz.foundation" mode="on" patch:before="processor[@type='Sitecore.Pipelines.Attach.CheckSize,Sitecore.Kernel']"/>
</attachFile>
</processors>
<sitecore>
</configuration>
and code can be like this with pipeline arguments will be AttachArgs
, make sure to include Sitecore.Pipelines.Attach
namespace in class -
public class className
{
public void Process(AttachArgs args)
{
//Some condition
if (args.MediaItem.Title != "test")
{
//Some action
}
}
}