ActiveX/Java Uploader allows not only filtering files by type, or limiting images but also limiting size and count of files. It is extremely useful when you:
To limit the maximum and minimum number of files allowed for the upload in a single upload session, use the Restrictions.MaxFileCount and Restrictions.MinFileCount properties respectively. If a user selects more files than specified by the Restrictions.MaxFileCount property, an error message (which can be customized using the Messages.MaxFileCountExceeded property) appears. If a user selects fewer files than the Restrictions.MinFileCount property value, the Upload button is disabled and files cannot be uploaded.
To remove both limitations, set Restrictions.MaxFileCount to 0 and Restrictions.MinFileCount to 1.
This example shows how to limit number of files from 3 to 10:
<aur:Uploader ID="Uploader1" runat="server">
<Restrictions MinFileCount="3" MaxFileCount="10"/>
<Messages MaxFileCountExceeded="You can add not more than 10 files."/>
</aur:Uploader>
$uploader = new Uploader("Uploader1");
$uploader->getRestrictions()->setMinFileCount(3);
$uploader->getRestrictions()->setMaxFileCount(10);
$uploader->getMessages()->setMaxFileCountExceeded("You can add not more than 10 files.");
var u = $au.uploader({
id: 'Uploader1',
restrictions: {minFileCount: 3, maxFileCount: 10},
messages: {maxFileCountExceeded: 'You can add not more than 10 files.'}
});
To set a limit on a total size of files selected for the upload, ActiveX/Java Uploader exposes the Restrictions.MaxTotalFileSize property. When the sum of selected file sizes exceeds this value, an error specified with the Messages.MaxTotalFileSizeExceeded property is displayed.
If you do not need to restrict the total file size, set Restrictions.MaxTotalFileSize to 0.
This limitation is applied to sizes of original files only. It does not take into account sizes of files created by ActiveX/Java Uploader from original ones (downsized copies of images, associated icons, compressed ZIP files) because there is no way to know their sizes before upload process starts. Therefore, the amount of the actually uploaded bytes may noticeably differ from this value. So the Restrictions.MaxTotalFileSize property is useful when you upload original files without applying any client-side file transformations. Otherwise, if it is important to limit the POST request size, the only way is to configure maximum acceptable POST request length in the server settings.
This example shows how to limit upload size to 100 Mb:
<aur:Uploader ID="Uploader1" runat="server">
<Restrictions MaxTotalFileSize="104857600" />
<Messages MaxTotalFileSizeExceeded="You are not allowed for uploading more than 100 MB."/>
</aur:Uploader>
$uploader = new Uploader("Uploader1");
$uploader->getRestrictions()->setMaxTotalFileSize(104857600);
$uploader->getMessages()->setMaxTotalFileSizeExceeded("You are not allowed for uploading more than 100 MB.");
var u = $au.uploader({
id: 'Uploader1',
restrictions: {maxTotalFileSize: 104857600},
messages: {maxTotalFileSizeExceeded: 'You are not allowed for uploading more than 100 MB.'},
});
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 via the Restrictions.MinFileSize and Restrictions.MaxFileSize properties respectively. Files which are too large or too small cannot be selected, thus, they are invisible by default. Even if a user clicks Total files and tries to add such files to the upload list, ActiveX/Java Uploader displays an error message specified with the Messages.FileSizeTooSmall or Messages.MaxFileSizeExceeded property. Additionally, each inappropriate file is equipped with a tooltip containing the same error message text.
Both these properties should be set to 0 when no file size limitations are required.
In the following example files smaller than 200 Kb or larger than 2 Mb are denied:
<aur:Uploader ID="Uploader1" runat="server">
<Restrictions MinFileSize="204800" MaxFileSize="2097152" />
<Messages FileSizeTooSmall="File is too small. You can add files not smaller than 200 KB."
MaxFileSizeExceeded="File is too large. You can add files not larger than 2 MB."/>
</aur:Uploader>
$uploader = new Uploader("Uploader1");
$uploader->getRestrictions()->setMinFileSize(204800);
$uploader->getRestrictions()->setMaxFileSize(2097152);
$uploader->getMessages()->setFileSizeTooSmall("File is too small. You can add files not smaller than 200 KB.");
$uploader->getMessages()->setMaxFileSizeExceeded("File is too large. You can add files not larger than 2 MB.");
var u = $au.uploader({
id: 'Uploader1',
restrictions: {minFileSize: 204800, maxFileSize: 2097152},
messages: {fileSizeTooSmall: 'File is too small. You can add files not smaller than 200 KB.',
maxFileSizeExceeded: 'File is too large. You can add files not larger than 2 MB.'}
});