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
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

Add request header for upload action

Platform: jQuery |
Control: ejUploadbox

Description:

To add a request header during upload action in Upload box.

Solution:

You can add a custom request reader in upload box action during beforeSend event of Uploadbox which will be triggered before file has been sent to the server.

Please refer to the below code:

 <script type="text/javascript">  
        $(function () {  
            // declaration  
            $("#UploadDefault").ejUploadbox({  
                saveUrl: "api/UploadBox",  
                 beforeSend: function (args) {  
                 args.xhr.setRequestHeader("securityToken", "23456");  
                 }  
            });  
        });  
</script>  
 

 

public class UploadBoxController : ApiController
    {
 
        [AcceptVerbs("Post")]
        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);
                }
            }
        }
 
 }

 

You can get the header details from HttpContext.Current.Request.Headers. Security token details can be viewed in network tab as shown in the below image.

 

Http header

 

Sample: Uploadheader399918897

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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