【问题标题】:Kendo Upload get file size before post剑道上传在发布前获取文件大小
【发布时间】:2020-01-26 22:54:24
【问题描述】:

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

【问题讨论】:

标签: javascript jquery kendo-ui upload


【解决方案1】:

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


}

【讨论】:

    猜你喜欢
    • 2011-05-10
    • 2011-11-21
    • 1970-01-01
    • 2020-03-17
    • 2014-11-19
    • 1970-01-01
    相关资源
    最近更新 更多