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

Error handling for the failed files

2 Answers 2520 Views
Upload
This is a migrated thread and some comments may be shown as answers.
JoJo
Top achievements
Rank 1
JoJo asked on 03 Jan 2013, 02:35 PM
Hi Team, 

I am using Kendo UI file upload control with multiple attribute set to true.

Does File Upload control handles the failed uploads on its own ?

I am using the following code snippet on the server and i am posting data through web api.

[HttpPost]
        public Task Post()
        {
            var folderName = "Uploads";
            //var PATH = HttpContext.Current.Server.MapPath("~/" + folderName);
            var PATH = "C://Uploads/";
            var rootUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty);
            if (Request.Content.IsMimeMultipartContent())
            {
                var streamProvider = new MultipartFormDataStreamProvider(PATH);
                var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>
                {
                    if (t.IsFaulted || t.IsCanceled)
                    {
                        throw new HttpResponseException(HttpStatusCode.InternalServerError);
                    }                    
                });
                return task;
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
            }
        }

 I want to capture the error information for the failed files and display that information to the user.

Kendo file upload is just returning the status as Failed for the failed uploads but how we can pass the actual error information back to the user?

Thanks

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 07 Jan 2013, 02:32 PM
Hello,

 You can try using the error event for that. The event arguments contain XMLHttpObject which you can then use to get the responseText.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Zachary
Top achievements
Rank 1
answered on 04 Dec 2013, 09:09 PM
I was able to make use of XMLHttpRequest with the following code:

$("#upload").kendoUpload({
    async: {
        saveUrl: "save",
        removeUrl: "remove",
        autoUpload: true
    },
    error: function (e) {
        var err = $.parseJSON(e.XMLHttpRequest.responseText);
 
        alert(err.Message);
 
        $.map(e.files, function (file) {
            alert("Could not upload " + file.name);
        });
    }
});

Rupinder
Top achievements
Rank 1
commented on 29 Jun 2022, 10:19 AM

ResponseText is not a json here, I am struggling to use error event here
Neli
Telerik team
commented on 01 Jul 2022, 08:09 AM

Hi Rupinder,

Could you please provide more details about the exacts issue? Is the e.XMLHttpRequest.responseText a string? If this is the case you may omit using the parseJSON method. 

Here is a StackOverflow thread where returning error message is discussed and you may find it helpful:

https://stackoverflow.com/questions/21415572/kendo-upload-control-pass-custom-error-message-back-to-view

Regards,

Neli

Tags
Upload
Asked by
JoJo
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Zachary
Top achievements
Rank 1
Share this question
or