如何根据内容长度或 MIME 类型中止 Catalyst 上传?
我尝试使用 parse_on_demand ,如下所示: http://search.cpan.org /~flora/Catalyst-Runtime-5.80007/lib/Catalyst.pm#ON-DEMAND_PARSER
但是,我似乎无法停止上传。 我只是通过创建一个立即终止的操作来测试这一点,但是浏览器似乎在到达我的操作之前上传了我选择的非常大的文件:
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...
}
这是进行上传验证的正确方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Catalyst 在分派到您的操作之前处理上传。 我怀疑,您需要在请求处理过程的早期进行拦截,这意味着需要一个插件。
我不是使用 Catalyst 上传的专家,但可能已经有一些东西可以做到这一点,因此值得在 cpan 上搜索...但如果不是,我会看看 上传进度 插件的作用是获取当前上传的状态。 您应该能够以类似的方式终止上传。
杰克
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.
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.
JayK
还要查看 HTML::FormHandler::Model::DBIC ,它在内置验证中为您处理这两种情况。
also look at HTML::FormHandler::Model::DBIC which handles both these cases for you within it's built in validation.