通过CSRF令牌blueimp文件上传 [英] pass csrf token to blueimp fileupload

查看:190
本文介绍了通过CSRF令牌blueimp文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用AngularJS一个SPA(单页应用程序),以及文件上传我试图用Blueimp文件上传。服务器端是的NodeJS,使用CSRF所以所有的请求将被发送到CSRF令牌(X-XSRF-TOKEN由AngularJS设置)的服务器。现在,当我试图使用上传它Blueimp失败,文件


  

错误:无效的CSRF令牌


因为它不力附上必要的令牌的要求,现在我想知道如何设置令牌。请注意,我已经使用AngularJS,和我没有任何meta标签设置为CSRF,但令牌处于饼干提供。

感谢您!!


解决方案

我用固定它的以下内容:


  $。ajaxSetup({
    标题:{
        X-XSRF-TOKEN:$ .cookie(XSRF-TOKEN)
    }
});


感谢

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!!

解决方案

I've fixed it by using the following:

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

Thanks

这篇关于通过CSRF令牌blueimp文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆