我正在使用sails.js beta 0.10
文件上传适用于小文件,但对于大文件,它会出现此错误:
error: Server Error:
error: TypeError: Object #<ServerResponse> has no method 'view'
at Object.forbidden (/home/mandeep/iqr/esurvey/api/responses/forbidden.js:81:19)
at ServerResponse.bound [as forbidden] (/home/mandeep/iqr/esurvey/node_modules/lodash/dist/lodash.js:729:21)
at /home/mandeep/iqr/esurvey/node_modules/sails/lib/hooks/csrf/index.js:65:28
at createToken (/home/mandeep/iqr/esurvey/node_modules/sails/node_modules/express/node_modules/connect/lib/middleware/csrf.js:82:44)
at /home/mandeep/iqr/esurvey/node_modules/sails/node_modules/express/node_modules/connect/lib/middleware/csrf.js:48:24
at routes.before./* (/home/mandeep/iqr/esurvey/node_modules/sails/lib/hooks/csrf/index.js:62:34)
at routeTargetFnWrapper (/home/mandeep/iqr/esurvey/node_modules/sails/lib/router/bind.js:176:5)
at callbacks (/home/mandeep/iqr/esurvey/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/home/mandeep/iqr/esurvey/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/home/mandeep/iqr/esurvey/node_modules/sails/node_modules/express/lib/router/index.js:145:5) [TypeError: Object #<ServerResponse> has no method 'view']
但是如果我禁用csrf它会完美运行。有什么想法吗?
答案 0 :(得分:1)
这可能是一个时间问题,如果上传的文件非常大,_csrf
字段的解析速度不够快。可能的解决方法是在标头中发送CSRF令牌而不是使用请求参数。您可以通过将请求中的X-CSRF-Token
标头设置为CSRF令牌值来完成此操作。
答案 1 :(得分:1)
另一种方法是在文件输入上方的表单中移动csrf隐藏字段。然后它将由服务器首先解析。