This is a migrated thread and some comments may be shown as answers.

Kendo Upload Control

1 Answer 298 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Aarti
Top achievements
Rank 1
Aarti asked on 19 Oct 2016, 10:45 PM

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

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 20 Oct 2016, 08:25 AM

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.
Tags
Upload
Asked by
Aarti
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or