Edit this page

Set Size Limit for Images Uploaded with Editor ImageBrowser

Environment

Product Progress Kendo UI Editor
Operating System All
Browser All
Preferred Language JavaScript

Description

How can I set a size limit for the images uploaded with the Editor's ImageBrowser?

Solution

You can check the size of the selected file in the select event handler of the Upload embedded in the ImageBrowser and prevent the upload in case the file size exceeds the specified limit.

<script>
    $(document).ready(function () {
        //attach a click handler to the Editor's ImageBrowser tool
        $(".k-i-image").click(function () {
            setTimeout(function(){
                //attach a select handler to the Upload embedded in the ImageBrowser
                $(".k-imagebrowser .k-upload").find("input").data("kendoUpload").bind("select", function (e) {
                    //prevent the event in case the selected file exceeds the specified limit
                    if (e.files[0].size > 1048576) {
                        e.preventDefault();
                        alert("Maximum allowed file size: 1MB");
                    }
                });
            });
        });
    });
</script>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy