jqueryangularjsnode.jscsrfblueimp

pass csrf token to blueimp fileupload


I'm building a SPA (Single Page Application) using AngularJS, and for FileUpload I'm trying to use Blueimp File Upload. Server side is in NodeJS, using csrf so all requests would be sent to the server with csrf token (X-XSRF-TOKEN set by AngularJS). Now when I'm trying to upload the file using Blueimp it fails with

"Error: invalid csrf token"

as it dint attach the necessary token in the request, now I'm wondering on how to set the token. Please note that I'm already using AngularJS, and I dont have any meta tag set to csrf, but the token is available in the cookies.

Thank you!!


Solution

  • I've fixed it by using the following:

    $.ajaxSetup({
        headers: {
            'X-XSRF-TOKEN': $.cookie("XSRF-TOKEN")
        }
    });
    

    Thanks