FAQ
I would like to place a maximum file size limit on uploads, but am not
quite sure how to go about this in Catalyst.

I've done this in CGI scripts by reading in chunks of the file until I
hit some size limit, but couldn't find anything in the Catalyst docs.

Thanks!
- Jim

Search Discussions

  • Jay Shirley at Jul 10, 2007 at 10:20 pm

    On 7/10/07, Jim Spath wrote:
    I would like to place a maximum file size limit on uploads, but am not
    quite sure how to go about this in Catalyst.

    I've done this in CGI scripts by reading in chunks of the file until I
    hit some size limit, but couldn't find anything in the Catalyst docs.

    Thanks!
    - Jim
    Hi Jim,

    A better approach would be to configure the webserver to do this, that
    way you aren't tying up your application.

    As an example, if you use Apache simply do:
    LimitRequestBody 1048576

    -Jay

    --
    J. Shirley :: jshirley@gmail.com :: Killing two stones with one bird...
    http://www.toeat.com
  • Jim Spath at Jul 10, 2007 at 10:39 pm

    J. Shirley wrote:
    On 7/10/07, Jim Spath wrote:
    I would like to place a maximum file size limit on uploads, but am not
    quite sure how to go about this in Catalyst.

    I've done this in CGI scripts by reading in chunks of the file until I
    hit some size limit, but couldn't find anything in the Catalyst docs.

    Thanks!
    - Jim
    Hi Jim,

    A better approach would be to configure the webserver to do this, that
    way you aren't tying up your application.

    As an example, if you use Apache simply do:
    LimitRequestBody 1048576

    -Jay
    Jay,

    Using the webserver is a definite possibility, and something we should
    put in place anyways, to restrict large requests.

    One downside of using such an option for limiting of file uploads is
    that it restricts me from providing meaningful error messages to the
    user within my application.

    Another downside is that the limit would then be static across my
    application, preventing me from setting different limits depending on
    what the user is doing.

    - Jim
  • Jay Shirley at Jul 10, 2007 at 10:57 pm

    On 7/10/07, Jim Spath wrote:
    J. Shirley wrote:
    On 7/10/07, Jim Spath wrote:
    I would like to place a maximum file size limit on uploads, but am not
    quite sure how to go about this in Catalyst.

    I've done this in CGI scripts by reading in chunks of the file until I
    hit some size limit, but couldn't find anything in the Catalyst docs.

    Thanks!
    - Jim
    Hi Jim,

    A better approach would be to configure the webserver to do this, that
    way you aren't tying up your application.

    As an example, if you use Apache simply do:
    LimitRequestBody 1048576

    -Jay
    Jay,

    Using the webserver is a definite possibility, and something we should
    put in place anyways, to restrict large requests.

    One downside of using such an option for limiting of file uploads is
    that it restricts me from providing meaningful error messages to the
    user within my application.

    Another downside is that the limit would then be static across my
    application, preventing me from setting different limits depending on
    what the user is doing.

    - Jim
    Hi Jim,

    I didn't realize that was what you were after. The upload object
    ($c->req->uploads->{name}) has a ->size method that returns the size
    in bytes. You can check that to determine the actual attachment size.

    I don't believe (and some of the Engine guys can correct me if
    necessary) there is any way to split off while the upload is actually
    happening unless you override prepare_body_chunk.

    That method is called while processing the HTTP body and working with
    an HTTP::Body object. I'm not sure how you could not do something
    application wide, since this happens during prepare_body:

    http://search.cpan.org/~jrockway/Catalyst-Manual-5.700701/lib/Catalyst/Manual/Internals.pod#Request_Lifecycle

    So -- as you can see there, I'm not sure how your action would know
    about the limits unless you wrote a plugin for this, that then was
    configured on a per-action basis. Something like PageCache, really.

    Just wild speculation, but hope it helps.

    Happy hacking,
    -Jay

    --
    J. Shirley :: jshirley@gmail.com :: Killing two stones with one bird...
    http://www.toeat.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJul 10, '07 at 10:09p
activeJul 10, '07 at 10:57p
posts4
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Jim Spath: 2 posts Jay Shirley: 2 posts

People

Translate

site design / logo © 2022 Grokbase