Search results

Check image size in ASP.NET Core RichTextEditor control

By using the Rich text editor’s imageUploading event, you can get the image size before uploading and restrict the image to upload, when the given image size is greater than the allowed size.

In the following, we have validated the image size before uploading and determined whether the image has been uploaded or not.

tagHelper
controller.cs
<ejs-richtexteditor id="editor" imageUploading="onImageUploading">
    <e-richtexteditor-insertimagesettings saveUrl="https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save" path="../Images/"></e-richtexteditor-insertimagesettings>
</ejs-richtexteditor>

<script>
    function onImageUploading(args) {
    console.log("file is uploading");
    var imgSize = 500000;
    var sizeInBytes = args.fileData.size;
    if ( imgSize < sizeInBytes ) {
        args.cancel = true;
    }
    }
</script>
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }
}