Libraries and file processors
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.
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:
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
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
In case you need to pass additional parameters to the file processor, you need to override the following method:
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:
- Navigate to Administration » Settings » Advanced settings » Libraries » File processors.
- Click the Create new button.
- Enter the following:
Save your changes.
To add parameters to the file processor, expand its node.
Click Create new.
Enter the key of the parameter, for example, Text.
Enter the value, for example, Name.
Save your changes.
The type must be identical as the name of the file processor class you implemented.
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.