e-on
e-on

Reputation: 1605

Returning correct error message in Kendo Upload if file too big

Having a few issues with Kendo Upload. When the file is less than the max size which is 15MB, then it's fine. 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?

Thanks

Upvotes: 1

Views: 6883

Answers (1)

Alaa Masoud
Alaa Masoud

Reputation: 7135

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.

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

Upvotes: 8

Related Questions