res.forbidden 文件上传到 sails 时出错
res.forbidden error on file upload into sails
我在 node/sails 中遇到了一个奇怪的问题并且很难解决。我可以通过上传表单上传小的 xls 文件,但较大的文件不能 process/upload,这是一个简单的测试,当传递一个小文件(500-1000 行)时,它处理正常并且我得到控制台日志。一个大文件(20,000 行)在上传时旋转。
我的表单如下所示:
<div class="row col-xs-12">
<form id="uploadForm"
enctype="multipart/form-data"
action="/utility/test_req"
method="post">
<label for="Parse Through Row" class="control-label">Parse</label>
<input type="text" name="num_rows" />
<input type="file" name="csv_file" />
<input type="hidden" name="_csrf" value="<%= _csrf %>" />
<input type="submit" class="btn btn-default" value="Upload CSV"/>
</form>
</div>
我的控制器看起来像这样:
test_req: function (req, res, next){
console.log("here");
console.log(req.params.all());
res.redirect('/utility/migration')
},
这是一个 csrf 问题。全局禁用 csrf 允许使用更大的文件达到控制器操作。我不确定这是配置问题(可能)还是 csrf 或 sails 的错误(不太可能)。
将 _crsf
标记移到表单顶部,我相信浏览器会按顺序发送输入字段,因此,sails 会按相同的顺序对其进行解析。 csrf 令牌是有时间限制的,所以在它们失效之前你会得到短暂的 window 使用,然后如果你有一个大文件,首先你的文件被处理(或文件),当 sails 完成后它会解析你的令牌,但为时已晚。
<form>
<input type="hidden" name="_csrf" value="<%= _csrf %>" />
// The rest of the inputs here, including the file input.
<input type="submit" class="btn btn-default" value="Upload CSV"/>
</form>
现在应该可以了:)
我在 node/sails 中遇到了一个奇怪的问题并且很难解决。我可以通过上传表单上传小的 xls 文件,但较大的文件不能 process/upload,这是一个简单的测试,当传递一个小文件(500-1000 行)时,它处理正常并且我得到控制台日志。一个大文件(20,000 行)在上传时旋转。
我的表单如下所示:
<div class="row col-xs-12">
<form id="uploadForm"
enctype="multipart/form-data"
action="/utility/test_req"
method="post">
<label for="Parse Through Row" class="control-label">Parse</label>
<input type="text" name="num_rows" />
<input type="file" name="csv_file" />
<input type="hidden" name="_csrf" value="<%= _csrf %>" />
<input type="submit" class="btn btn-default" value="Upload CSV"/>
</form>
</div>
我的控制器看起来像这样:
test_req: function (req, res, next){
console.log("here");
console.log(req.params.all());
res.redirect('/utility/migration')
},
这是一个 csrf 问题。全局禁用 csrf 允许使用更大的文件达到控制器操作。我不确定这是配置问题(可能)还是 csrf 或 sails 的错误(不太可能)。
将 _crsf
标记移到表单顶部,我相信浏览器会按顺序发送输入字段,因此,sails 会按相同的顺序对其进行解析。 csrf 令牌是有时间限制的,所以在它们失效之前你会得到短暂的 window 使用,然后如果你有一个大文件,首先你的文件被处理(或文件),当 sails 完成后它会解析你的令牌,但为时已晚。
<form>
<input type="hidden" name="_csrf" value="<%= _csrf %>" />
// The rest of the inputs here, including the file input.
<input type="submit" class="btn btn-default" value="Upload CSV"/>
</form>
现在应该可以了:)