Uploader failure event's reponse property does not include the body

https://ej2.syncfusion.com/angular/documentation/api/uploader/#failure

The object emitted by the failure event (see below) has an undocumented property called 'response', which does not include the response body. Is there any way to access the body of the response in the event of plo? 



5 Replies

SP Sureshkumar P Syncfusion Team June 1, 2022 12:49 PM UTC

Hi Joseph,

We cannot pass the response body in our failure event argument response attribute. Please update your exact use case scenario to access the response body. We will update the exact solution based on your scenario as earlier as possible.

Regards,

Sureshkumar P



JN Joseph Newton replied to Sureshkumar P June 1, 2022 12:58 PM UTC

I would like to access the response body after a file fails to upload because our server sometimes includes useful information explaining the reason for the failure in the response body. 

This is a very common use case, hence the existence of things like the problem details standard: https://datatracker.ietf.org/doc/html/rfc7807  



SP Sureshkumar P Syncfusion Team June 2, 2022 10:02 AM UTC

Based on your requirement, we suspect that you want to get the status code and status text in the failure event. We suggest you remove the Response.Clear and Response.ContentType from your server-side code to achieve your requirement. 


[Server Side (Razor Page)]

 

public IActionResult OnPostUpload(IList<IFormFile> uploadFiles)

{

   //... 

        // no need to update the Response here  

        @* Response.Clear(); 

        Response.ContentType = "application/json"; *@ 

        // Sennd HTTP 200 (OK), 400, or what you want. 

        return StatusCode(204, new { Message = $"{errorMessage}" }); 

}

 

[Client Side]

    function onUploadSuccess(args) {

        let response = JSON.parse(args.e.target.response);

        args.statusText = response.message;

    }

 

    function onUploadFail(args) {

        let response = JSON.parse(args.e.target.response);

        args.statusText = response.message;

    }

 




JN Joseph Newton June 6, 2022 08:02 AM UTC

This is a very bad answer. I definitely do not want to clear the response because that is where the information I want to access is located. There are no changes required to the server-side code. I want to access the response body on the client-side after an upload fails. Is that possible? 



SP Sureshkumar P Syncfusion Team June 7, 2022 11:48 AM UTC

Hi Joseph,


We suggest you pass the text in the response header section and parse the response header in the success or failure event like our previous suggestion. Also, can you please share the back-end service platform details like whether it is in ASP Net Core or MVC? Based on your shared details, we will validate it on our end and update the further details.


Regards,

Sureshkumar P


Loader.
Up arrow icon