We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

set custom statusText for restuls in upload

Thread ID:

Created:

Updated:

Platform:

Replies:

143272 Mar 12,2019 02:57 PM UTC Mar 25,2019 06:52 AM UTC Angular - EJ 2 10
loading
Tags: Uploader
Manolo Capdevila
Asked On March 12, 2019 02:57 PM UTC

Hi, I'm using angular and aspnet core web api in a project.

I need upload a file and process this file.

But whether everything has gone correctly or if I have made an error, I can not get the response message from the server.

For other hand, I've defined the server path in asyncsettings. But... Can I use a custom service for upload the file instead set the saveUrl  asyncsettings?

Thanks

Prince Oliver [Syncfusion]
Replied On March 13, 2019 06:47 AM UTC

HI Manolo, 

Thank you for contacting Syncfusion support. 

The uploader component allows you to modify the file even after uploading to the server, which can be done using success and failure event of the uploader. You need to use the custom headers to send the data from server to client side. While receiving the custom headers in client side it will contains server details along with the sent message. Kindly refer to the following code snippet. 

[html] 
<ejs-uploader #upload id=uploadDefault [asyncSettings]='path' (failure)='onUploadStatus($event)' (success)='onUploadStatus($event)'></ejs-uploader> 
 

[component.ts] 
onUploadStatus(args) { 
    var header = args.response.headers; 
    var statusMessage = header.slice(header.indexOf('status'), header.indexOf('date')); 
    statusMessage = statusMessage.slice(statusMessage.indexOf(',') + 1); 
    args.statusText = statusMessage.trim(); 
} 
 

[server side] 
[AcceptVerbs("Post")] 
public IActionResult Save(IList<IFormFile> UploadFiles) 
{ 
    try 
    { 
        foreach (var file in UploadFiles) 
        { 
            if (UploadFiles != null) 
            { 
                var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); filename = hostingEnv.WebRootPath + $@"{filename}"; 
                if (!System.IO.File.Exists(filename)) 
                { 
                    using (FileStream fs = System.IO.File.Create(filename)) 
                    { 
                        file.CopyTo(fs); fs.Flush(); 
                    } 
                } 
                else 
                { 
                    Response.Clear(); Response.StatusCode = 404; Response.Headers.Add("status", "File Already Exists"); 
                } 
            } 
        } 
    } 
    catch (Exception e) 
    { 
        Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.StatusCode = 400; Response.Headers.Add("status", e.Message); 
    } 
    return Content(""); 
} 
 

Also, instead of using asyncSettings saveUrl property in uploader component, you can use fileSelected event to get the selected file details and set args.cancel = true to prevent the default uploader process. Then use the file data to upload the file to your own custom service. Please refer the following links for customizing the uploader. 


Please let us know if you need any further assistance on this. 

Regards, 
Prince  


Manolo Capdevila
Replied On March 13, 2019 11:19 AM UTC

Hi,

I can't get the response headers in angular.

I attach a simple example

Thanks

Attachment: uploadProblem_4c90061b.zip

Manolo Capdevila
Replied On March 18, 2019 03:40 PM UTC

Any idea?

Prince Oliver [Syncfusion]
Replied On March 19, 2019 06:02 AM UTC

HI Manolo, 

Thank you for your patience. 

We have checked the reported issue in our end and upon validation, we could infer that the issue occurs with WebAPI app in ASP.NET Core 2.2. We were not able to get the custom headers in Core 2.2 WebAPI application and we have raised an issue with AspNetCore regarding this. Kindly refer to the following Issue link: https://github.com/aspnet/AspNetCore/issues/8567  

Until we have a definite solution for this issue, we suggest you use lower dotnet version to resolve this.  

Regards, 
Prince  


Manolo Capdevila
Replied On March 19, 2019 09:08 AM UTC

Ups... I can't reduce the .netcore version...

I follow this thread for the solution

Thanks for your answer

Prince Oliver [Syncfusion]
Replied On March 20, 2019 06:32 AM UTC

Hi Manolo, 

Most Welcome. We are glad to assist you.  

Regards, 
Prince 


Manolo Capdevila
Replied On March 20, 2019 08:48 AM UTC

Is possible use other name in response header name different at status as they suggest?


I try to use different but it doesn't work



Prince Oliver [Syncfusion]
Replied On March 21, 2019 10:46 AM UTC

Hi Manolo, 

We have already tried using a different name and have changed the header name as ("status - custom"). But it is not working in our end too. The custom headers is shown in the chrome browser’s network tab, but it is not obtained in the getAllResponseHeaders() method. 

We have updated the same in the forum. 

Regards, 
Prince 


Manolo Capdevila
Replied On March 22, 2019 01:31 PM UTC

Ok, Thanks...

Prince Oliver [Syncfusion]
Replied On March 25, 2019 06:52 AM UTC

Hi Manolo,  

Most Welcome. We are glad to assist you. We will notify you, if we have a definitive solution for this issue. 

Regards,  
Prince 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon