问题
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!!
回答1:
I've fixed it by using the following:
$.ajaxSetup({ headers: { 'X-XSRF-TOKEN': $.cookie("XSRF-TOKEN") } });
Thanks
回答2:
In case anyone stumbled upon this page like me, it should be
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $.cookie("XSRF-TOKEN")
}
});
CSRF instead of XSRF.
回答3:
If I understand correctly, you can write an interseptor that sets the token in the request header: AngularJS $http
来源:https://stackoverflow.com/questions/27265998/pass-csrf-token-to-blueimp-fileupload