问题描述
我尝试使用 parse_on_demand ,如下所示:http://search.cpan.org/~flora/Catalyst-Runtime-5.80007/lib/Catalyst.pm#ON-DEMAND_PARSER
I've tried to use parse_on_demand as shown in:http://search.cpan.org/~flora/Catalyst-Runtime-5.80007/lib/Catalyst.pm#ON-DEMAND_PARSER
但是,我似乎无法停止上传.我只是通过创建一个立即终止的操作来测试这个,但是浏览器似乎在它到达我的操作之前上传了我选择的非常大的文件:
However, I can't seem to stop the upload. I'm testing this simply by creating an action that dies immediately, however the browser seems to upload the very large file I've selected before it ever reaches my action:
sub upload :Local {
my ($self, $c) = @_;
die;
# What I'd like to do is this:
# if ($c->req->header('Content-Length') > $some_limit) {
# die "Upload too large";
# }
# ... check filename extension and mime-type...
}
这是进行上传验证的正确方法吗?
Is this the right way to approach upload validation?
推荐答案
Catalyst 在分派到您的操作之前处理上传.你需要在请求处理过程中更早地拦截,我怀疑这意味着一个插件.
Catalyst handles the upload before dispatch to your action. You will need to intercept earlier in the request handling process and that means a plugin, I suspect.
我不是使用 Catalyst 上传的专家,但可能已经有一些东西可以做到这一点,所以值得在 cpan 上搜索...但如果不是,我会看看 Upload Progress 插件可以获取当前上传的状态.您应该能够以类似的方式终止上传.
I am not an expert on uploads with Catalyst, but there may be something out there that already does this, so it's worth a search on cpan... but if not I'd look at how the Upload Progress plugin does what it does to get a status on the current upload. You should be able to kill the upload in a similar way.
周杰伦
这篇关于如何根据内容长度或 MIME 类型中止 Catalyst 上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!