Skip to content Skip to sidebar Skip to footer

Sitecore Pipeline Upload Processor

I'm using UploadProcessor to block specific file uploading into MediaLibrary. Everything is working good and I can see the alert Sitecore's message. But, Sitecore's error message i

Solution 1:

The Upload control in the Media Library uses flash to upload the files. As part of this upload process, the file sizes are checked using JavaScript and a client side validation is made before the upload.

There are a number of changes you need to make. I'm just going to list them here, you can find all the code in my Github Gists:

https://gist.github.com/jammykam/54d6af46593fa3b827b4


1) Extend and update the MediaFolder.js file to check the file size against the Image Size ONLY if the extension is one specified in config

if (file.size > this.uploadLimit() || this.uploadImageLimitReached(file)) {
    ...
}

2) Update MediaFolder.xml page to include the above JS. Amend the codebeside, inheriting from Sitecore.Shell.Applications.Media.MediaFolder.MediaFolderForm and overriding OnLoad and OnFilesCancelled, to render restricted extensions and max image size settings so these are passed to the Javascript and display friendly alert.

settings.Add("uploadImageLimit", ((long)System.Math.Min(ImageSettings.MaxImageSizeInDatabase, Settings.Runtime.EffectiveMaxRequestLengthBytes)).ToString());
settings.Add("uploadImageRestrictedExtensions", ImageSettings.RestrictedImageExtensions);

3) Update Attach.xaml.xml codebeside to check image size, inheriting from Sitecore.Shell.Applications.FlashUpload.Attach.AttachPage and overriding OnQueued method:

if (ImageSettings.IsRestrictedExtension(filename) && num > maximumImageUploadSize)
{
    string text = Translate.Text("The image \"{0}\" is too big to be uploaded.\n\nThe maximum image size that can be uploaded is {1}.", new object[] { filename, MainUtil.FormatSize(maximumImageUploadSize) });
    this.WarningMessage = text;
    SheerResponse.Alert(text, new string[0]);
}
else
{
    base.OnQueued(filename, lengthString);
}

4) Add a config include with the new settings.

<setting name="Media.MaxImageSizeInDatabase" value="1MB" />
<setting name="Media.RestrictedImageExtensions" value=".jpg|.jpeg|.png|.gif|.bmp|.tiff" />

You can still (and should) keep the pipelines in place, but note from my previous answer I gave the "Restricted Extension" config setting has now changed (into a single setting instead of passing it into the pipeline). The Gist contains the

NOTE that I have tested this using Sitecore 7.2 rev 140526, so the base code is taken from there. If you are using a different version then you should check the base C#, JS and XML code matches what I have provided. The code is commented to show you what has changed.

The above works in the Content Editor, it does not work in the Page Editor! Which in Sitecore 7.2+ uses SPEAK dialogs and it looks like they use a different set of pipelines. That would need more investigation (raise another question, and specify which version of Sitecore you are using).


Post a Comment for "Sitecore Pipeline Upload Processor"