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. Image for the cookie policy date

Using a Web API controller with ejUploadbox

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


1 Reply

KV Karthikeyan Viswanathan Syncfusion Team 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. 


Loader.
Up arrow icon