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
close icon

Passing custom data with file on upload in file manager

Hey there.

We have passed keycloak username and token in beforesend() function. Now we want to pass custom data (like a form) along with the file on clicking upload button in file manager. How can we do that?


1 Reply

SS Sivakumar ShunmugaSundaram Syncfusion Team October 20, 2022 09:37 AM

Hi Jyoti,


Greetings from syncfusion support.


From the shared details, we understand that you want to pass custom data like a form to the server side while performing an Upload operation in the FileManager component. We have prepared a simple sample of the React FileManager component with the physical service provider.


To achieve your requirements, we suggest you pass the form data as a JSON string format in the FileManager beforeSend event and get the data on the server side as mentioned in the below code snippet. We have attached the modified sample to your reference.


Refer to the below code snippet.

[Index.js]

 

onbeforeSend(args) {

    if (args.action == 'Upload') {

      //Ajax beforeSend event

      args.ajaxSettings.beforeSend = function (args) {

        //Setting authorization header

        var data = { Name: 'Syncfusion' };

        var myJSON = JSON.stringify(data);

        args.httpRequest.setRequestHeader('Authorization', myJSON);

      };

    }

  }

 


[PhysicalFileProvider.cs]

 

    public class my

    {

        public string Name { get; set; }

    }

...

 

        [Route("Upload")]

        public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action)

        {

            var root = HttpContext.Request.Headers["Authorization"];

            var def = JsonConvert.DeserializeObject<my>(root);

            var myroot = def.Name;


Sample: https://stackblitz.com/edit/react-g7snc2-kpnabc?file=index.js


Service provider: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-aspcore-file-provider-master771724235.zip


Please check the shared details and get back to us if you need any further assistance.


Regards,

Sivakumar S



Loader.
Live Chat Icon For mobile
Up arrow icon