You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Vuillemot, Ward W <wa...@boeing.com> on 2002/03/14 17:12:17 UTC

POST and multipart/data-form question

I have searched off and on for the past 3 weeks for a solution to my
problem.  I am at wits end. . .and thought I would finally ask the
mailinglist.

I had a set of CGI scripts that worked without problem.  I began the process
about 4 weeks ago of moving them to mod_perl.  The suite of scripts are
handled as their own perlHandler collection.  One of the scripts has a form
where a user can either enter data directly, or indicate a file of
equivalent data.

When I use the form to POST without any enctype and if you enter directly
into the form things work correctly.  That is, the data is "massaged" and
sent back to you as downloadable file.  Of course, this form does not handle
file uploads.

Now, I change nothing more than the form enctype to "multipart/data-form".
Now, regardless of how the data is presented in the form (e.g. directly or
via file upload) the browser tries to refresh the screen with the web-page
(which it should not since its only response is to send to the client a file
to download).  However, the web page does not get completely sent, and
consistently stops in the middle of the send.

I have been using the POST2GET snippet to help make the post more
persistent.  In short, my httpd.conf file looks like:

#
# **********************
# ** MOD PERL CHANGES **
# **********************
# limit POSTS so that they get processed properly
<Limit POST>
  PerlInitHandler POST2GET
</Limit>
# force reloading of modules on restart
PerlFreshRestart on
# Perl module primitive mother load on start/restart
#PerlRequire lib/perl/startup.pl
# FLOE application (mod_perl)
PerlModule Apache::DBI
PerlModule floeApp
<Location /floeApp>
  SetHandler perl-script
  PerlHandler floeApp
  PerlSendHeader On
</Location>

And the relevant two snippets of code from the script are:
	## process incoming
	# if submitted
	my %hash = undef;
  	my $initialList = $q->param('initialList') || '';
	my $upload = $q->upload || undef;
	my $fh = $upload->fh if defined($upload);
	if (defined($upload) && $upload) {
		$initialList = '';
		while (<$fh>) {
			$initialList .= $_;
		}
	}

	## some processing is done to the POST'ed data
	## and eventually. . .

	## send file to client
	print   "Content-type: text/plain\n";
        	print   "Content-Disposition: attachment;
filename=list.txt\n\n";

	foreach my $value (sort keys %$hash) {
		chomp($value);
		next unless ($value);
		print "$hash->{$value}$CRLF$value$CRLF";
	}

	exit;


Any ideas?  I would love to get this solved so I can get back to developing
useful scripts.  :)

Thanks!
Ward

Ward W. Vuillemot
Boeing Flight Operations Engineering
Performance Software
tel +01 206-662-8667 * fax +01 206-662-7612
ward.w.vuillemot@boeing.com


Re: POST and multipart/data-form question

Posted by Robin Berjon <ro...@knowscape.com>.
On Thursday 14 March 2002 17:12, Vuillemot, Ward W wrote:
> Now, I change nothing more than the form enctype to "multipart/data-form".

I haven't looked at your sample code in detail, but as someone that got 
caught on similar problems due to silly typoes I'd like to point out that 
it's "multipart/form-data" and not the other way 'round.

-- 
_______________________________________________________________________
Robin Berjon <ro...@knowscape.com> -- CTO
k n o w s c a p e : // venture knowledge agency www.knowscape.com
-----------------------------------------------------------------------
There's too much blood in my caffeine system.


Re: POST and multipart/data-form question

Posted by Hans Poo <ha...@integranet.cl>.
El Jue 14 Mar 2002 12:12, Vuillemot, Ward W escribió:
> I have searched off and on for the past 3 weeks for a solution to my
> problem.  I am at wits end. . .and thought I would finally ask the
> mailinglist.
>
> I had a set of CGI scripts that worked without problem.  I began the
> process about 4 weeks ago of moving them to mod_perl.  The suite of scripts
> are handled as their own perlHandler collection.  One of the scripts has a
> form where a user can either enter data directly, or indicate a file of
> equivalent data.
>
> When I use the form to POST without any enctype and if you enter directly
> into the form things work correctly.  That is, the data is "massaged" and
> sent back to you as downloadable file.  Of course, this form does not
> handle file uploads.
>
> Now, I change nothing more than the form enctype to "multipart/data-form".
> Now, regardless of how the data is presented in the form (e.g. directly or
> via file upload) the browser tries to refresh the screen with the web-page
> (which it should not since its only response is to send to the client a
> file to download).  However, the web page does not get completely sent, and
> consistently stops in the middle of the send.
>
> I have been using the POST2GET snippet to help make the post more
> persistent.  In short, my httpd.conf file looks like:
>
> #
> # **********************
> # ** MOD PERL CHANGES **
> # **********************
> # limit POSTS so that they get processed properly
> <Limit POST>
>   PerlInitHandler POST2GET
> </Limit>
> # force reloading of modules on restart
> PerlFreshRestart on
> # Perl module primitive mother load on start/restart
> #PerlRequire lib/perl/startup.pl
> # FLOE application (mod_perl)
> PerlModule Apache::DBI
> PerlModule floeApp
> <Location /floeApp>
>   SetHandler perl-script
>   PerlHandler floeApp
>   PerlSendHeader On
> </Location>
>
> And the relevant two snippets of code from the script are:
> 	## process incoming
> 	# if submitted
> 	my %hash = undef;
>   	my $initialList = $q->param('initialList') || '';
> 	my $upload = $q->upload || undef;
> 	my $fh = $upload->fh if defined($upload);
> 	if (defined($upload) && $upload) {
> 		$initialList = '';
> 		while (<$fh>) {
> 			$initialList .= $_;
> 		}
> 	}
>
> 	## some processing is done to the POST'ed data
> 	## and eventually. . .
>
> 	## send file to client
> 	print   "Content-type: text/plain\n";
>         	print   "Content-Disposition: attachment;
> filename=list.txt\n\n";
>
> 	foreach my $value (sort keys %$hash) {
> 		chomp($value);
> 		next unless ($value);
> 		print "$hash->{$value}$CRLF$value$CRLF";
> 	}
>
> 	exit;
>
>
> Any ideas?  I would love to get this solved so I can get back to developing
> useful scripts.  :)
>
> Thanks!
> Ward
>
> Ward W. Vuillemot
> Boeing Flight Operations Engineering
> Performance Software
> tel +01 206-662-8667 * fax +01 206-662-7612
> ward.w.vuillemot@boeing.com

just to test, if you trie:

perl -MCGI -e 'print CGI::start_multipart_form()'

you get

<form method="post" action="/-e" enctype="multipart/form-data">

and not:

multipart/data-form

as you write

May be you spelled it wrong on he message, but this may be your problem.

Hans