- Home
- Forum
- ASP.NET Core - EJ 2
- Uploader Response
Uploader Response
What is
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = JsonUtils.Serialize(uploadResult);
I have e.g. net core ApiController
the way of returning response is Ok(result);
where result contains processed renamed file with additional info.
How I can get this info if in args.response on client side I have only data before uploading and "File Uploaded Successfully
I need my custom serialized object in response instead of predefined response.
SIGN IN To post a reply.
4 Replies
PO
Prince Oliver
Syncfusion Team
March 4, 2019 11:26 AM UTC
Hi Edgar,
Thank you for you contacting Syncfusion support.
Query 1: What is Reponse.clear(), Response.statusCode and phraseDescription?
After the server-side actions gets completed, we need to send the response to client side with proper status code and details. By using Response.clear() we have cleared the details from http and have updated the details in the response.
In our samples, we will not allow to save the files in our server due to security reasons. So, to display the selected files in success state we have return the status code as 204.
Phrase descriptions are used to send the custom messages from server side to client side. But it will work up to dot net core 2.0 only. Dot net core 2.1 and above versions doesn’t have a reasonPhrase support, we need to send the custom data using headers only. Please refer the below code block.
|
Response.Headers.Add("status", "File Already Exists"); |
For further details, kindly refer the below link.
Query 2: the way of returning response is Ok(result) where result contains processed renamed file with additional info
You can get the additional data from the server by using the argument “e” in success/failure events. Please refer the below screenshot.
|
|
Please let us know if you need any further assistance on this.
Regards,
Prince
NB
Naresh Bisht
March 24, 2020 07:30 AM UTC
Hi sir, I'm also going through this situation can you please send me a project where you have implemented this I'm a beginner in web development thus having a very hard time understanding this a project where it changes the text to "File already exist" when a file with the same name already exist in the database will help me to understand it much better.
Thank you.
NB
Naresh Bisht
March 24, 2020 10:23 AM UTC
Okay, I got it now all I had to do was add this in my view -
<ejs-uploader id="UploadFiles" failure="onUplaodFail" asyncSettings="@asyncSettings" uploading="addTokens" multiple="false" autoUpload="false"></ejs-uploader>
<script>
function addTokens(args) {
args.currentRequest.setRequestHeader('XSRF-TOKEN', document.getElementsByName('__RequestVerificationToken')[0].value);
}
function onUplaodFail(args) {
var header = args.response.headers;
var statusMessage = header.slice(header.indexOf('status'), header.indexOf('x-powered-by'));
statusMessage = statusMessage.slice(statusMessage.indexOf(',') + 1);
args.statusText = statusMessage;
}
</script>
and in my controller -
Response.Clear();
Response.StatusCode = 404;
Response.Headers.Add("status", "File Already Exists");
The above code works for ASP.NET core 3.1 in case anyone faces the same issue
SP
Sureshkumar P
Syncfusion Team
March 24, 2020 11:35 AM UTC
Hi Naresh,
Thanks for your update. Please get back to us if you need any further assistance on this.
Regards,
Sureshkumar P
SIGN IN To post a reply.
- 4 Replies
- 5 Participants
-
ED Edgar Drozdov
- Mar 2, 2019 11:02 PM UTC
- Mar 24, 2020 11:35 AM UTC