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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using a Web API controller with ejUploadbox

Thread ID:

Created:

Updated:

Platform:

Replies:

129957 Apr 11,2017 06:27 PM UTC Apr 12,2017 12:52 PM UTC Angular 1
loading
Tags: ejUploadbox
John Mulligan
Asked On April 11, 2017 06:27 PM UTC

Can you point me to a working example of a Web API controller being called from an ejUploadbox (to save and remove files)?
I have only been able to find a WCF and ashx samples on you site, but we are not using these technologies on our project.
Your help is appreciated.

Thanks, Jack


Karthikeyan Viswanathan [Syncfusion]
Replied On April 12, 2017 12:52 PM UTC

Hi John, 

Thanks for contacting Syncfusion support. 

We have prepared a sample for ejuploadbox with web API controller. Please refer to the code snippet for save and remove action: 

<code> 
export class HomeComponent { 
    saveURL: string; 
    removeURL: string; 
    constructor() { 
        this.saveURL = '../../api/Uploadbox/Save'; 
        this.removeURL = '../../api/Uploadbox/Remove'; 
    } 
} 
</code> 
<code> 

<ej-uploadbox id="uploadDefault" [saveUrl]="saveURL" [removeUrl]="removeURL"></ej-uploadbox> 
</code> 
<code> 
[AcceptVerbs("Post")] 
        [Route("api/Uploadbox/Save")] 
        public void Save() 
        { 
            if (HttpContext.Current.Request.Files.AllKeys.Any()) 
            { 
                var httpPostedFile = HttpContext.Current.Request.Files["Uploadbox"]; 
 
                if (httpPostedFile != null) 
                { 
                    var fileSave = HttpContext.Current.Server.MapPath("UploadedFiles"); 
                    if (!Directory.Exists(fileSave)) 
                    { 
                        Directory.CreateDirectory(fileSave); 
                    } 
                    var fileSavePath = Path.Combine(fileSave, httpPostedFile.FileName); 
                    httpPostedFile.SaveAs(fileSavePath); 
                } 
            } 
        } 
</code> 
<code> 
        [AcceptVerbs("Post")] 
        [Route("api/Uploadbox/Remove")] 
        public void Remove(string[] fileNames) 
        { 
 
            var fileSave = HttpContext.Current.Server.MapPath("UploadedFiles"); 
 
            var fileSavePath = fileSave + "\\" + HttpContext.Current.Request.Form.GetValues("fileNames")[0]; 
 
            if (System.IO.File.Exists(fileSavePath)) 
            { 
                System.IO.File.Delete(fileSavePath); 
            } 
        } 

</code> 



Regards, 
Karthikeyan V. 


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.

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

;