如何根据内容长度或 MIME 类型中止 Catalyst 上传?

发布于 2024-07-29 01:49:07 字数 638 浏览 5 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亣腦蒛氧 2024-08-05 01:49:07

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

待天淡蓝洁白时 2024-08-05 01:49:07

还要查看 HTML::FormHandler::Model::DBIC ,它在内置验证中为您处理这两种情况。

also look at HTML::FormHandler::Model::DBIC which handles both these cases for you within it's built in validation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文