reading buffered form data

Discussion in 'Perl Misc' started by Jeff Thies, Jun 30, 2003.

  1. Jeff Thies

    Jeff Thies Guest

    I have a multipart form with several fields including an imput
    type="file" that needs to be FTP'd elsewhere. The file input may be
    quite large.

    If I were to read in the file using CGI.pm, CGI.pm would slurp in the
    entire "file" into a temp file, potentially exceeding the storage quota.

    I think I'm going to have read from STDIN directly.

    my $flag=0;
    while(<STDIN>){
    if($_=~/^-------/){ # reset if form boundary, do all form boundaries
    start like that?
    $flag=0;
    }
    if($flag){&appendFTP($_)}
    if($_=~/name="name_of_file"/){ # look for form name
    $flag=1;
    }
    }

    That seems a bit simple and crude. Do I need to do this?:
    $_ =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; (before
    appendFTP)

    Do I need to filter out the "Content-type: ...\n\n" that seems to start
    the file?

    What else have I overlooked?

    Jeff
    Jeff Thies, Jun 30, 2003
    #1
    1. Advertising

  2. Jeff Thies

    Greg Bacon Guest

    In article <>,
    Jeff Thies <> wrote:

    : I have a multipart form with several fields including an imput
    : type="file" that needs to be FTP'd elsewhere. The file input may be
    : quite large.
    :
    : If I were to read in the file using CGI.pm, CGI.pm would slurp in
    : the entire "file" into a temp file, potentially exceeding the storage
    : quota.

    Doesn't your provider at least enforce separate quotas for temporary
    directories such as /usr/tmp, /var/tmp/, and /tmp?

    : I think I'm going to have read from STDIN directly.
    : [...]

    Probably a bad idea. Have you considered patching CGI.pm to return
    the file data in a scalar? Even so, what are you going to do with
    the data then? Net::FTP deals in terms of files.

    Greg
    --
    Of all the enemies to public liberty war is, perhaps, the most to be dreaded,
    because it comprises and develops the germ of every other.
    -- James Madison
    Greg Bacon, Jun 30, 2003
    #2
    1. Advertising

  3. Jeff Thies

    Jeff Thies Guest

    Greg Bacon wrote:
    >
    > In article <>,
    > Jeff Thies <> wrote:
    >
    > : I have a multipart form with several fields including an imput
    > : type="file" that needs to be FTP'd elsewhere. The file input may be
    > : quite large.
    > :
    > : If I were to read in the file using CGI.pm, CGI.pm would slurp in
    > : the entire "file" into a temp file, potentially exceeding the storage
    > : quota.
    >
    > Doesn't your provider at least enforce separate quotas for temporary
    > directories such as /usr/tmp, /var/tmp/, and /tmp?


    They seem to vary. At least one I work with doesn't, which has been a
    big problem in the past.
    >
    > : I think I'm going to have read from STDIN directly.
    > : [...]
    >
    > Probably a bad idea. Have you considered patching CGI.pm to return
    > the file data in a scalar?


    Nope. Is that a tough thing to do? I assumed that it was written in C,
    which I have only a passing knowledge of. I'll go look now...

    > Even so, what are you going to do with
    > the data then? Net::FTP deals in terms of files.


    Well maybe I'm wrong but I see that Net::FTP has an append method.

    Thanks for the reply, after I posted this I realized this may have been
    more of a CGI that perl question

    Cheers,
    Jeff
    Jeff Thies, Jun 30, 2003
    #3
  4. Jeff Thies

    Greg Bacon Guest

    In article <>,
    Jeff Thies <> wrote:

    : Greg Bacon wrote:
    :
    : > Doesn't your provider at least enforce separate quotas for temporary
    : > directories such as /usr/tmp, /var/tmp/, and /tmp?
    :
    : They seem to vary. At least one I work with doesn't, which has been a
    : big problem in the past.

    It surprises me that CGI.pm doesn't let you set a limit on uploaded
    file size.

    : > Probably a bad idea. Have you considered patching CGI.pm to return
    : > the file data in a scalar?
    :
    : Nope. Is that a tough thing to do? I assumed that it was written in C,
    : which I have only a passing knowledge of. I'll go look now...

    CGI.pm is written in Perl. Patching wouldn't be beginner-friendly,
    though.

    : > Even so, what are you going to do with
    : > the data then? Net::FTP deals in terms of files.
    :
    : Well maybe I'm wrong but I see that Net::FTP has an append method.

    Right, but append's arguments are filenames. If the temp file is too
    big to write, then how will you use Net::FTP::append?

    Net::FTP::appe [sic] method could be useful, but you'd still need to do
    a little legwork.

    : Thanks for the reply, after I posted this I realized this may have
    : been more of a CGI that perl question

    Being lazy and more bug-prone than I'd like, I'd much rather use
    tried-and-true code such as the CGI module than roll my own. YMMV.

    Greg
    --
    The coercive power of government is always a beacon to those who want to
    dominate others -- summoning the worst dregs of society to Washington to
    use that power to impose their will upon others.
    -- Harry Browne
    Greg Bacon, Jun 30, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWVobWV0?=

    sending web response wihout buffered

    =?Utf-8?B?TWVobWV0?=, Jan 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    324
    Hermit Dave
    Jan 13, 2004
  2. Brad
    Replies:
    3
    Views:
    1,870
    Steven Cheng[MSFT]
    Feb 19, 2004
  3. Peter Ashford

    Buffered image using float data

    Peter Ashford, May 2, 2005, in forum: Java
    Replies:
    5
    Views:
    1,812
    Peter Ashford
    May 2, 2005
  4. Replies:
    9
    Views:
    679
    Michael Wojcik
    Aug 23, 2005
  5. markspace
    Replies:
    6
    Views:
    317
    Arne Vajhøj
    Nov 7, 2011
Loading...

Share This Page