This documentation is for the old version. Go to the latest Upload Suite docs

Specifying Restrictions for Size and Number of Files

Image Uploader allows to limit files not only by type, but also by size and total number. It is extremely useful when you want to allocate limited space on your server for users.

Restricting Number of Files

To limit the maximum and minimum numbers of files allowed for the upload in a single upload session, use the MaxFileCount and MinFileCount properties respectively. If the users select more files than specified by the MaxFileCount property, they get an error message (which can be customized using the MessageMaxFileCountExceededText property). If the user selects less files than the MinFileCount property value the Send button is disabled and files cannot be uploaded.

To remove both limitations, set MaxFileCount to 0 and MinFileCount to 1.

Restricting Single File Size

You can set a limitation not only for total size of the files selected for the upload, but also for a single file size. Both lower and upper limitations can be specified. Use the MinFileSize and MaxFileSize properties respectively. Too large or too small files cannot be selected: depending on the control layout and its view mode either error message is displayed (as specified with the MessageFileSizeIsTooSmallText and MessageMaxFileSizeExceededText properties) or appropriate items are marked as too large or too small in the folder pane (captions are designated using the FileIsTooSmallText and FileIsTooLargeText properties).

Both these properties should be set to 0 when no file size limitations are required.

Restricting Upload Size

To set a limit on a total size of files selected for the upload, Image Uploader exposes the MaxTotalFileSize property. When the sum of selected file sizes exceeds this value, an error message is displayed. This error message can be modified with the MessageMaxTotalFileSizeExceededText property.

If you do not need to restrict the total file size, set MaxTotalFileSize to 0.

This limitation is applied only to sizes of original files. It does not take into account sizes of thumbnails generated by Image Uploader. Therefore, the actual upload size may noticeably differ from this value. If it is important to limit the POST request size (rather than total size of uploaded files), the only way to do it is to configure maximum acceptable POST request length in the server settings.

Important

As limitations specified in Image Uploader are checked only on the client side, you should not interpret them as a reliable protection. A potential malicious user can bypass all these limitations (by emulating Image Uploader or modifying its parameters in a local copy of a page). That is why it is highly recommended to implement server-side verification of uploaded files in addition to Image Uploader file tests.

In other words, all limitation features discussed in this topic should be used solely for the convenience of the user. They should not be interpreted as a serious protection from malicious users.

Code Examples

How to Upload Not More Than 5 Files

JavaScript
<script type="text/javascript" src="iuembed.js">  </script>
<script type="text/javascript">
var iu = new ImageUploaderWriter("ImageUploader", 710, 500);

//...Any other params...

iu.addParam("MaxFileCount", "5");
iu.addParam("MessageMaxFileCountExceededText", "You can select not more then 5 files.");

//...

iu.writeHtml();
</script>

How to Prevent Upload Files Larger Than 200 KB

JavaScript
<script type="text/javascript" src="iuembed.js">  </script>
<script type="text/javascript">
var iu = new ImageUploaderWriter("ImageUploader", 710, 500);

//...Any other params...

iu.addParam("MaxFileSize", "204800");
iu.addParam("FileIsTooLargeText", "Larger then 200 kb");
iu.addParam("MessageMaxFileSizeExceededText", "You can select files not larger then 200 kb.");

//...

iu.writeHtml();
</script>

How to Limit Total File Size with 2 MB

JavaScript
<script type="text/javascript" src="iuembed.js">  </script>
<script type="text/javascript">
var iu = new ImageUploaderWriter("ImageUploader", 710, 500);

//...Any other params...

iu.addParam("MaxTotalFileSize", "2097152");
iu.addParam("MessageMaxTotalFileSizeExceededText", "You are not allowed for uploading more than 2 MB.");

//...

iu.writeHtml();
</script>

See Also

Reference

Manual

Troubleshooting