如何根据Content-Length或MIME-Type中止Catalyst上载?

时间:2021-11-24 21:14:16

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

我尝试使用parse_on_demand,如下所示: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?

这是接近上传验证的正确方法吗?

2 个解决方案

#1


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在发送到您的操作之前处理上载。我怀疑,你需要在请求处理过程的早期拦截,这意味着一个插件。

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.

我不是使用Catalyst上传的专家,但可能有一些已经做到这一点的东西,所以值得在cpan上搜索...但如果没有,我会看看上传进度插件是如何做到的获取当前上传的状态。您应该能够以类似的方式终止上传。

JayK

#2


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

另请参阅HTML :: FormHandler :: Model :: DBIC,它在内置验证中为您处理这两种情况。

#1


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在发送到您的操作之前处理上载。我怀疑,你需要在请求处理过程的早期拦截,这意味着一个插件。

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.

我不是使用Catalyst上传的专家,但可能有一些已经做到这一点的东西,所以值得在cpan上搜索...但如果没有,我会看看上传进度插件是如何做到的获取当前上传的状态。您应该能够以类似的方式终止上传。

JayK

#2


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

另请参阅HTML :: FormHandler :: Model :: DBIC,它在内置验证中为您处理这两种情况。