Kendo Upload Control

2 posts, 0 answers
  1. Aarti
    Aarti  avatar
    20 posts
    Member since:
    Mar 2014

    Posted 19 Oct Link to this post

    Hi,

     

    I am using kendo upload control and I need to upload zip file through only if zip file has only one file inside it other wise i needed to fail the upload.  OnSuccess event of upload I am calling controller action to add validations for the upload file.  How can I send file itself through Ajax to controller action so that i can extract zip file on server side and fail the upload if zip has more than 1 file inside it.

     @(Html.Kendo().Upload()
                                  .Name("files").ShowFileList(false)
                                  .Async(a => a.AutoUpload(false)
                                      .Save("UploadSingleDocument", "Upload")
                                  )
                                  .Multiple(false)
                                  .Events(events => events
                                      .Select("attachClickHandler")
                                      .Upload("OnUpload").Success("OnSuccess").Error("onError"))
                            )

     

     

    Below is my javascript code. e.files[0] is always returning null.

     

     $.ajax({
                    url: ('@Url.Action("ValidateDocumentExtension", "Upload")'),
                    contentType: "application/json",
                    async: true,
                    type: "POST",
                    data: JSON.stringify({files:e.files[0], fieldlst: webFormFields, fileName: document.getElementById("DocumentName").value }),
                    success: function(data) {
                        if (data === 'False') {
                            showNotification("Upload Document", "Invalid Document Extension", "error");
                            flagUpload = false;
                        } else if (data === 'True') {
                            flagUpload = true;
                            if ($("div.k-notification-error").Exists()) {
                                $("div.k-notification-error").hide();
                            }
                            if ($("div.k-notification-info").Exists()) {
                                $("div.k-notification-info").hide();
                            }
                        }
                    }
                });

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 20 Oct Link to this post

    Hello Aarti,

    Generally a file cannot be uploaded through regular Ajax request. A FormData request is needed to achieve this. Nevertheless I am not sure why this is needed, since this is what the Upload widget role is - to upload the file asynchronously. You could implement the zip validation logic in the UploadSingleDocument save handler.

    Regards,
    Dimiter Madjarov
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top