Libraries and file processors

Overview

When you upload files to Sitefinity CMS libraries, you can define whether you require any additional processing logic, applied to these files. You do this using file processors. For example, you can put a brand watermark on each image you upload. Another example is when uploading text files, to add validation for a specific word in the text files.

NOTE: Sitefinity CMS comes with an out-of-the-box SVG sanitizer. For details, see SVG images and JavaScript.

Implement file processors

You plug this additional functionality that is executed when an image is uploaded by first implementing the file processor in your project and then adding it as functionality in the Sitefinity CMS backend.

A file processor inherits the FileProcessorBase class. You then need to implement the following two methods:

  • CanProcessFile method
    This method defines the type of file to be handled by the file processor. File type is determined either by the file’s extension, or by the MIME type that are passed as parameters by the FileProcessorInput object
  • Process method
    The method receives as input parameter object of type FileProcessorInput that consists of the file type definition (by extension or MIME type) and a stream that consists of the uploaded file’s content. In this method, you can transcode the image into another format. If you do this, you must also assign the new MIME type using the MimeType and FileExtension properties.

In case you need to pass additional parameters to the file processor, you need to override the following method:

Initialize(NameValueCollection config)

All parameters are listed in the config parameter that is passed to the method.

Add and manage file processors in Sitefinity CMS backend

To add the newly created file processor as an administration setting in Sitefinity CMS:

  1. Navigate to Administration » Settings » Advanced settings » Libraries » File processors.
  2. Click the Create new button.
  3. Enter the following:
    • Name
    • Description
    • Type
      The type must be identical as the name of the file processor class you implemented.
  4. Save your changes.
  5. To add parameters to the file processor, expand its node.
  6. Click Create new.
  7. Enter the key of the parameter, for example, Text.
  8. Enter the value, for example, Name.
  9. Save your changes.

After you enable your newly added file processor, it is executed each time you upload the type of file you specified. For an example of how to implement a Watermark maker file processor, see Tutorial: Add watermark to JPEG images.

To edit the properties of a file processor, expand the File processors node and click on the specific processor, for example Svg sanitizer.

NOTE: If you edit the check type, make sure you replace it with a viable type and its parameter.

To delete a file processor altogether, click on the File processors node and then on the trash can icon next to the name of the processor.

NOTE: You can also just disable the file processor if you do not want to execute it for some specific amount of time, for example.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Thumbnails