It's not currently possible to limit each individual file size before the upload starts. The browser doesn't pass up file length information, only the content-length of the entire request. You can access the file length of each file after the upload is complete and reject the file at that point.
Uploads also have to fit in the maxRequestLength setting in web.config -- this is a hard limit on the length of the request. If you are trying to allow uploads to the SlickUpload handler to be larger, but limit the requests to the rest of the application, you can do this by using location based configuration just for the SlickUpload handler. Something like this:
<location path="SlickUpload.axd">
<slickUpload>
<uploadParser handleRequests="true" />
</slickUpload>
<system.web>
<httpRuntime maxRequestLength="2024000" executionTimeout="300"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2072576000"/>
</requestFiltering>
</security>
</system.webServer>
</location>
Because the setting for increased maxRequestLength is inside the location tag for the SlickUpload.axd handler, it will only apply to SlickUpload uploads. The rest of the application will continue to have the default maxRequestLength.
To address your situation with the 5 mb per file, with a max of 3 files, I'd recommend this:
- Set your maxRequestLength to 15 mb (or slightly more to accommodate the request encoding overhead)
- In the UploadComplete event, check the UploadStatus.Reason property. If this is UploadTerminationReason.MaxRequestLengthExceeded, the entire request was too large and the upload was rejected. Display an appropriate message.
- If not, loop through the files. If a file is larger than 5mb, delete it and display the appropriate message for that file.