# 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.

> info **NOTE**: Sitefinity CMS comes with an out-of-the-box SVG sanitizer. For details, see [SVG images and JavaScript](https://www.progress.com/documentation/sitefinity-cms/upload-svg-images#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.

## Handle processing errors

If the `Process` method of a file processor throws an exception, Sitefinity CMS aborts the upload. The same happens when the `Process` method returns a `null` or unreadable stream. The details of the error are written to the error log, and you see the following generic message: *The file cannot be processed. It may have an invalid format or may be corrupt. Check the file for compatiblity or contact your administrator to review the error log.*

To reject a file, for example when it fails your validation, throw an exception from the `Process` method.

> info **NOTE**: This behavior applies to uploads handled by the libraries data provider.

## 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](https://www.progress.com/documentation/sitefinity-cms/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*.

> info **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.

> info **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.
