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

How can i send a csrf token when sending the files to the saveUrl?

I am using the JS Uploader in a Laravel application, all works well but i need to send a csrf token when making ajax requests, how can i accomplish this while using the Uploader control?




1 Reply

SP Sureshkumar P Syncfusion Team May 2, 2023 11:22 AM UTC

Hi Olah,


We suggest you refer to the below code example to achieve your requirement.


Find the code example here:

// Send an AJAX request with the CSRF token

var fileUpload = this.uploadObj.element.parentElement.querySelector(

      '.e-hidden-file-input'

    ).files[0];

    // var files = fileUpload.files;

    var data = new FormData();

    // for (var i = 0; i < files.length; i++) {

    data.append(fileUpload.name, fileUpload);

    // }

$.ajax({

  type: 'POST',

 url: 'https://localhost:44312/Home/Save',

  headers: {    'X-CSRF-Token': csrfToken   },

  data: data,

  success: function (message) { },

      error: function () { },

});


Regards,

Sureshkumar P



Loader.
Up arrow icon