Pass csrf token to blueimp fileupload

I am creating a SPA (Single Page Application) using AngularJS and for FileUpload I am trying to use Blueimp file upload. The server side is in NodeJS using csrf, so all requests will be sent to the server using the csrf token (X-XSRF-TOKEN set by AngularJS). Now when I try to upload a file using Blueimp it fails with

"Error: Invalid csrf token"

since it binds the required token in the request, now I'm wondering how to set the token. Please note that I am already using AngularJS and I don't have the meta tag set in the csrf, but the token is available in the cookies.

Thank!

+3


source to share


3 answers


I fixed it using the following:

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

      



thank

+2


source


If anyone stumbled upon this page like me, it should be

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

      



CSRF instead of XSRF.

+3


source


If I understand correctly, you can write an intersector that sets the token in the request header: AngularJS $ http

-1


source







All Articles