October 24, 2024

Some time back, I wrote an article on finding out from the Database the heavier Media Items. This was to find and notify that they cannot upload  a larger file to the Database as it may affect the performance adversely. To refer to the Article, click here.

But as always, its better to be proactive instead of being reactive… 🙂

And the end result is this post. I googled for a way so that we can we prevent the Content Authors of Sitecore from uploading a heavy media item to the Database.

Sitecore is so well built…. It has so many switches to turn ON and OFF various operations and also, set specific values for a given Setting.

Solution:

     Prerequisite:

First of all make sure that you are using Classic Upload as your uploading option. This can be verified by the following setting:

[sourcecode language=”xml”]
<!–  UPLOAD CLASSIC
Indicates if uploading runs in classic (no flash) mode.
Default: false
–>
<setting name="Upload.Classic" value="true"/>
[/sourcecode]

In case its disabled, i.e. value is false, please enable it by making the value true.

     Main Solution:

Well, there is a small setting in the Web.config called Media.MaxSizeInDatabase.  Increase or decrease the value of this setting to prevent users from exceeding that specified threshold value while uploading the Media Item.

The setting is as follows:

[sourcecode language=”xml”]
<!–  MEDIA – MAX SIZE IN DATABASE
The maximum allowed size of media intended to be stored in a database (binary blob).
This value must be less than the ASP.NET httpRuntime.maxRequestLength setting.
Default value: 500MB
–>
<setting name="Media.MaxSizeInDatabase" value="15MB"/>
[/sourcecode]

Again, as seen in its comment, it must be less than the ASP.NET httpRuntime.maxRequestLength setting.

To verify this, please check the following setting:

[sourcecode language=”xml”]
<!–
httpRuntime Attributes:
executionTimeout="[seconds]" – time in seconds before request is automatically timed out
maxRequestLength="[KBytes]" – KBytes size of maximum request length to accept
useFullyQualifiedRedirectUrl="[true|false]" – Fully qualifiy the URL for client redirects
minFreeThreads="[count]" – minimum number of free thread to allow execution of new requests
minLocalRequestFreeThreads="[count]" – minimum number of free thread to allow execution of new local requests
appRequestQueueLimit="[count]" – maximum number of requests queued for the application

If you change the maxRequestLength setting, you should also change the Media.MaxSizeInDatabase setting.
Media.MaxSizeInDatabase should always be less than maxRequestLength.
–>
<httpRuntime maxRequestLength="512000" executionTimeout="600" enableKernelOutputCache="false"/>
[/sourcecode]

The value is 512000 in Kb, which is equal to 500 MB.

So if any user tries to upload a media item to the database exceeds the specified value of this setting, the corresponding item will not be uploaded and will prompt the user about the same.

How it works!

Currently, I have specified a value for the setting Media.MaxSizeInDatabase as 15 MB.

Now I will demonstrate the outcome of the same.

1.      Upload media item using Simple Upload

  • First, we will check for simple upload in a Media Folder called My Folder.
My Folder - The specified Media Folder
  •  In the Upload a File dialog, we select a file.
Select Simple Upload Option
  • Note that the pdf is of 26 MB, i.e. higher than the threshold specified.
Simple Upload - Select File


  • As we can see, when we press upload, a prompt box appears saying the file is too big to be uploaded.
Simple Upload - Click Upload and Sitecore prompts

2.      Upload media item/s using Advanced Upload

  •   Now we will upload media items using the Upload Files (Advanced) option to the Media Folder My Folder
My Folder
  • The Advanced Upload Dialog Box appears as we select the Advanced Upload option.
Advanced Upload Dialog Box
  •  We select all these files out of which one file is above the threshold — File 2 in our case.
Advanced Upload - Files Selected with File 2 higher than Threshold
  •  As seen here, Sitecore will prompt the user, and specify that the file cannot be uploaded.
Advanced Upload - Multiple Files Prompt to User
3.      Upload archived media item/s using Advanced Upload
  • We will archive the previously selected files only. Also, The first two steps remain same as in the above case of Advanced Upload.
  • Next, Select an Archive (Zip File).
Advanced Upload – Uploading Zip
  • Selecting the option – Unpack ZIP Archives – so that Sitecore scans it based on the individual files present in this archive, rather than taking it as a single file.. 🙂
Advanced Upload – Unpack ZIP Archives
  • When we select the upload option, the system prompts us with the message as below.
Advanced Upload - Uploading ZIP prompt message
It also works from the Page Editor mode, the reason being in case we upload a file from Page Editor, the same uploader will be used.
Thus, we can specify a limit to the size of files to be uploaded.

Happy Sitecoring! 🙂

1 thought on “Restrict the Sitecore content authors from uploading a heavy Media Item to Database

Leave a Reply

Your email address will not be published. Required fields are marked *