in reply to Re: On-disk multipart/form-data part extraction
in thread On-disk multipart/form-data part extraction

Also, since you helpfully mentioned it, regarding CGI:: there is seemingly no success for me, either.

You see, CGI:: can parse multipart bodies with its upload() member, but seemingly only when they come from STDIN or via CGI::Fast -- neither of which are available to me (nor desirable to me, indeed) as a nginx-embedded perl module.

Hence my search for another way. The perl "staples" do not seem to cover my use case.

  • Comment on Re^2: On-disk multipart/form-data part extraction

Replies are listed 'Best First'.
Re^3: On-disk multipart/form-data part extraction
by blue_cowdawg (Monsignor) on Dec 25, 2012 at 03:06 UTC
        STDIN or via CGI::Fast -- neither of which are available to me

    STDIN not available? EH?? I've never seen an environment where stdin wasn't available. Even if you opened STDIN directly

    close STDIN; open STDIN,"< myfile.text" or die "myfile.txt: $!"; ... do stuff
    as such. Is this a CGI script or what are you up to here?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re^3: On-disk multipart/form-data part extraction
by Anonymous Monk on Dec 24, 2012 at 17:42 UTC

    nginx-embedded perl module

    never heard of it :)

    So http://wiki.nginx.org/HttpPerlModule? In that case,

    ;P

    local *STDIN; open STDIN, '<', $r->request_body_file or die $!; binmode STDIN; my $q = CGI->new( \*STDIN );

    :)

    my $body = Nginx_Body ( $r ); my $uploads = $body->upload; # hashref ## cleanup temp files undef $uploads; undef $body; sub Nginx_Body { my $r = shift; my $tmpdir = shift; my $content_type = $r->headers_in('Content-Type'); my $content_length = $r->headers_in('Content-Length'); my $body = HTTP::Body->new( $content_type, $content_length ); $body->tmpdir( $tmpdir ) if $tmpdir; my $length = $content_length; open my($bodyfh), '<:raw', $r->request_body_file or die $!; while ( $length ) { my $read = read( $bodyfh, my $buffer, ( $length < 8192 ) ? $length : 8192 ); my $bufferlength = length($buffer); die "IMPOSSIBLE $read != $bufferlength " if $read != $bufferle +ngth ; $length -= $bufferlength; $body->add( $buffer ); } return $body; }

    Although, after reading a bit from Nginx - full-featured perl support for nginx nginx might have this feature already , or at least it should :)

      Your afterthought speculation is correct. I probably should have pointed out straight away that the Nginx:: module and related others such as are found on CPAN is/are not the same as the interface module distributed with nginx (called simply nginx::, notice lower case). This confused me greatly at first.

      Indeed, If I gather right, the Nginx (capitalized) module is a relic from early nginx distribution days. While now (apparently) deprecated, unfortunately it contained API features not present in the (current) nginx distribution's module. So, for example, there is no $r->upload() method. There's also no $r->headers_in() method (note plural) to enumerate all headers; one must anticipate them in order to use $r->header_in() for each.

      In any case, after seeing your code, and to my optimistic delight, HTTP::Body does indeed look like it will put the uploaded "parts" in temporary files, with metadata information in a $body->upload() hash accessor. So thanks for that suggestion! I'll try that one too before reporting back, too.