In this tutorial, you will learn how to change the maximum file size upload limit within Umbraco V6 and V7. When content editors upload files that are too large, they will encounter an error.
Umbraco File Upload Maximum Request Length Exceeded. This error is annoying, however, it can be fixed. If you want to learn how to overcome this challenge, this is the tutorial for you 🔥🔥🔥
My File Is Too Big 😞
When a content editor tries to upload a file, like a 14MB PDF they will encounter the
Maximum request length exceeded exception. In your production website, if you have CustomErrors set to
RemoteOnly you might not even see this error at all. This is why troubleshooting this error can be annoying in some instances. If a content editor is having problems uploading a file, look in the logs for this error. After confirming you have a file size issue, you have two options to resolve it:
Allow Bigger Files to be Uploaded You can configure Umbraco to allow bigger files to be uploaded. To do this, open up your
web.config file within your website's webroot. In your
web.config find the section called
httpRuntime. Here, you should see an attribute called
maxRequestLength. You will need to increase this number to allow for larger uploads. This value is set in mega-bytes. By default,
maxRequestLength is set to 4MB. To change the upload limit to 20MB, you would use
If you want to go the bigger file size route, you may also want to extend the
executionTimeout property. This value increases your websites default timeout period. A timeout can occur when the server takes longer to upload a file than the maximum allowed timeout period. You can update
executionTimeout, like this:
My File Is Too Big In IIS7😞
If you are using IIS7+ you may bump into this slightly different error:
HTTP Error 404.13 - Not Found
The request filtering module is configured to deny a request that exceeds the request content length.
To fix this, you will need to update the
requestLimits maxAllowedContentLength property:
maxAllowedContentLength value is set in bytes, so 20MB would now be,
20971520. This approach will also make the timeout error occur less frequently, however, it's still a shit solution for content editors.
Custom Validation. The second approach to avoid this error is via validation. One of my strong philosophies when building a website is that creating a slick and easy back-end that content editors are happy with, is a key part of implementing a successful CMS project. If the content editors are not happy with your solution, the whole company will know about it 😕.
When a content editor tries to upload a file, if Umbraco just dies without telling them the reason, they will get pissed off and complain about it. Spending 15 minutes to develop some validation that stops this situation from occurring while providing feedback to content editors about what went wrong is a better experience in my opinion and well worth the effort.
To create this validation you will need to hook into the
Application_Error() method within
Global.ascx. If you struggle to get the below working, I recommend you read this tutorial! The code to do this is shown below:
Application_Error we check what type of exception has been thrown, using
Server.GetLastError(). This check is done in
IsMaxRequestException(). You need to check the
ErrorCode and the text of the inner exception to make sure it is a file limit warning error. If it is, I clear the exception from the stack and redirect the request to a custom HTML page I created. I use a simple HTML file that is called
FileToLarge.html in order to render more useful information to the content editor. You can call your HTML file whatever you want and put whatever content you want inside it. My file looks like this:
If you are using .NET 4, you can use this much simpler appraoch instead:
You now know how to fix the upload size issue in Umbraco. You can increase the file size or you can add better validation. Do what makes you happy. Happy Coding 🤘