By default there is no way to validate / check file size before it is uploaded, but jQuery Uploadify Plugin makes use of Flash program to determine the size of the File as soon as it is selected.
jQuery Uploadify plugin has a sizeLimit attribute which accepts the size in bytes.
jQuery Uploadify plugin has a sizeLimit attribute which accepts the size in bytes.
<script type = "text/javascript">
$(window).load(
function () {
$("#<%=FileUpload1.ClientID %>").fileUpload({
'uploader': 'scripts/uploader.swf',
'cancelImg': 'images/cancel.png',
'buttonText': 'Browse Files',
'script': 'Upload.ashx',
'folder': 'uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': true,
'auto': true,
'sizeLimit': (600 * 1024), //600 KB
onError: function (a, b, c, d) {
if (d.type === "File Size") {
// Display error message in span
$("#err").html('File: ' + c.name + ' Maximum ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024) + 'KB');
}
}
});
}
);
</script>
As you can see above I have specified the size limit of 600 KB. If the file size exceeds the limit it throws File Size error.
0 Comments
Post a Comment