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.
First of all make sure that you are using Classic Upload as your uploading option. This can be verified by the following setting:
<!-- UPLOAD CLASSIC Indicates if uploading runs in classic (no flash) mode. Default: false --> <setting name="Upload.Classic" value="true"/>
In case its disabled, i.e. value is false, please enable it by making the value true.
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:
<!-- 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"/>
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:
<!-- 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"/>
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.
- In the Upload a File dialog, we select a file.
- Note that the pdf is of 26 MB, i.e. higher than the threshold specified.
- As we can see, when we press upload, a prompt box appears saying the file is too big to be uploaded.
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
- The Advanced Upload Dialog Box appears as we select the Advanced Upload option.
- We select all these files out of which one file is above the threshold — File 2 in our case.
- As seen here, Sitecore will prompt the user, and specify that the file cannot be uploaded.
- 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).
- 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.. 🙂
- When we select the upload option, the system prompts us with the message as below.
Happy Sitecoring! 🙂