When you use Image Uploader to upload images (rather than common files) to your web site, you may wish to limit dimensions or color model of these images; for example:
To restrict dimensions the Restrictions class exposes the following properties:
You may want to resize the images which are too large instead of prohibiting them. See the Resizing and Recompressing topic for more information.
Image Uploader does not show "wrong" images by default, but users can see them after clicking Total files. The denied images cannot be selected, so they have no checkboxes near them. If a user tries to add such images to upload list, Image Uploader displays an error message saying why this image is denied. Besides, each denied image is equipped with a tooltip containing the same error message text. This text can be customized using the Messages.DimensionsTooLarge and Messages.DimensionsTooSmall properties.
Both these properties should be set to 0
when no image dimension limitations are
required.
In the following example only images smaller then 800 x 600 are allowed:
<aur:Uploader ID="Uploader1" runat="server"> <Restrictions MaxImageHeight="600" MaxImageWidth="800"/> <Messages DimensionsTooLarge="Image is too large, it should be smaller than 800x600 pixels."/> </aur:Uploader>
$uploader = new Uploader("Uploader1"); $uploader->getRestrictions()->setMaxImageHeight(600); $uploader->getRestrictions()->setMaxImageWidth(800); $uploader->getMessages()->setDimensionsTooLarge("Image is too large, it should be smaller than 800x600 pixels.");
var u = $au.uploader({ id: 'Uploader1', restrictions: {maxImageHeight: 600, maxImageWidth: 800}, messages: {dimensionsTooLarge: 'Image is too large, it should be smaller than 800x600 pixels.'} });
To forbid your users from uploading CMYK images set the Restrictions.EnableCmyk
property to false
. In that case Image Uploader does not display CMYK images until a
user clicks Total files. Even so, such files still cannot be selected: they have no checkboxes near them and
Image Uploader displays an error message saying that CMYK images are disabled whenever a user tries to add it
to the upload list. Additionally, each CMYK image is equipped with a tooltip containing the same error message text.
This text can be customized using the Messages.CmykImagesNotAllowed property.
Example below shows how to deny CMYK images:
<aur:Uploader ID="Uploader1" runat="server"> <Restrictions EnableCmyk="False" /> <Messages CmykImagesNotAllowed="CMYK images are not allowed." /> </aur:Uploader>
$uploader = new Uploader("Uploader1"); $uploader->getRestrictions()->setEnableCmyk(false); $uploader->getMessages()->setCmykImagesNotAllowed("CMYK images are not allowed.");
var u = $au.uploader({ id: 'Uploader1', restrictions: {enableCmyk: false}, messages: {cmykImagesNotAllowed: 'CMYK images are not allowed.'} });
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 the limitation features discussed in this article should be used solely for the convenience of the user. They should not be interpreted as a serious protection from malicious users.