pass csrf token to blueimp fileupload

风格不统一 提交于 2019-12-07 14:24:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!