Search results

Check image size in ASP.NET MVC RichTextEditor control

08 Apr 2021 / 1 minute to read

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.

Copied to clipboard
@Html.EJS().RichTextEditor("editor").InsertImageSettings(obj => obj.SaveUrl("").Path("../Images/")).ImageUploading("onImageUploading").Render()

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

    public ActionResult Index()
        return View();