简体   繁体   中英

Kendo Upload get file size before post

I need to get the file size using javascript

@(Html.Kendo().Upload()
                .Name("files")
                .Messages(m => m.Select("Browse"))
                .Multiple(false)
                .HtmlAttributes(new { aria_label = "files" })
                .Validation(
                    validation => validation.AllowedExtensions(new string[] { ".dlis", ".doc", ".docx", ".heic", ".jpeg", ".jpg", ".las", ".mov", ".mp4", ".pdf", ".png", ".tif", ".wav", ".xls", ".xlsx", ".zip" })
                    .MaxFileSize(2147483647))          
            )

You have .Events(events => events.Select("checkimage")) function so you can check image extension and also size as i showed in example

function checkimage(e){
   if(e.files[0].size > 2147483647)
   {
        alert("Size is too big");
   }

   var acceptedFiles = [".jpg", ".jpeg", ".png", ".gif", ".bmp",".mp4",".avi", ".JPG", ".JPEG", ".PNG", ".GIF", ".BMP",".MP4",".AVI"];
   var isAcceptedImageFormat = ($.inArray(e.files[0].extension, acceptedFiles)) !== -1;

    if(!isAcceptedImageFormat)
    { 
        alert("Please use accepted files");
    }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM