Kendo Upload在发布前获取文件大小

时间:2019-09-26 15:53:08

标签: javascript jquery kendo-ui upload

我需要使用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))          
            )

1 个答案:

答案 0 :(得分:0)

您具有.Events(events => events.Select("checkimage"))功能,因此可以检查图像扩展名和大小,如我在示例中所示

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");
    }


}