简体   繁体   English

如果文件太大,则在Kendo Upload中返回正确的错误消息

[英]Returning correct error message in Kendo Upload if file too big

Having a few issues with Kendo Upload. Kendo Upload遇到一些问题。 When the file is less than the max size which is 15MB, then it's fine. 当文件小于最大大小(15MB)时,就可以了。 However, if it is more than the max size, it doesn't go into the Upload action, but it still returns the message "Done". 但是,如果它大于最大大小,则不会进入“上传”操作,但仍会返回消息“完成”。

 @(Html.Kendo().Upload()
    .Name("files")
    .ShowFileList(false)
    .Async(a => a.Save("Upload", "Document", new {@id = Model.ChangeRequestId})
        .AutoUpload(true))
    .Events(e => e
        .Complete("refreshFileList"))
    )

If it went into the action, then I'd be able to check for file size and return an appropriate message. 如果执行该操作,那么我将能够检查文件大小并返回适当的消息。 Has anyone managed to successfully handle what happens with Kendo Upload if the file is too big? 如果文件太大,是否有人能够成功处理Kendo Upload的问题?

Thanks 谢谢

Why not do file size validation on client side instead? 为什么不在客户端进行文件大小验证呢?

Use the upload event to check the size and display message/abort download if needed. 如果需要,使用上upload事件检查大小并显示消息/中止下载。

.Events(e => e.Upload("onUpload"))
function onUpload(e) {
  var files = e.files;

  $.each(files, function () {
    if (this.size > 15*1024*1024) {
      alert(this.name + " is too big!");
      e.preventDefault(); // This cancels the upload for the file
    }
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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