New to Kendo UI for jQuery? Download free 30-day trial

Remove Files for Upload with Errors

Environment

Product Progress® Kendo UI® Upload for jQuery
Operating System Windows 10 64bit
Visual Studio Version Visual Studio 2017
Preferred Language JavaScript

Description

How can I remove files from the Kendo UI Upload when file validation fails?

Solution

The following example demonstrates how to remove files from the Kendo UI Upload when the upload/remove data operation fails due to errors or failing validation.

<style>
  html {
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
  }
</style>
<input name="files" id="files" type="file" />
<script>
  function onError(e) {
    var files = e.files;
    for (var i = 0; i < files.length; i++) {
      alert("Validation failed for " + files[i].name);

      var uid = files[i].uid;
      var entry = $(".k-file[data-uid='" + uid + "']");
      if (entry.length > 0) {
        entry.remove();
      }
    }
  }

  $(document).ready(function() {
    $("#files").kendoUpload({
      async: {
        saveUrl: "save",
        removeUrl: "remove",
        autoUpload: true
      },
      error: onError
    });
  });
</script>

See Also

In this article