You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Robert Norris <Ro...@its.monash.edu.au> on 2005/03/17 02:16:10 UTC
[RESEND] Empty file uploads
[Resending, because I need guidance. I realise that file uploads are
working fine for most people, so I'm not expecting an answer, but I'm
hopeful that someone can tell me where to start looking.]
I've noticed that file uploads don't seem to always work. The uploaded
file appears to come through empty most of the time. Usually it works
after restarting the browser, or the server, but not after that. If I'm
lucky, one request will go through, but thats pretty rare, and there
doesn't seem to be any pattern.
I'm using Embperl 2.0rc2 with Perl 5.6.1.
I have the following code for the form:
<form method='post' enctype='multipart/form-data'>
File: <input type='file' name='file' id='file' />
<input type='submit' />
</form>
To read the file, I use the following Perl:
my $fh = $fdat{'file'};
my $raw = do { local $/; <$fh> };
(I've noticed that the returned filehandle doesn't always seem to act
like a real filename - certain methods don't always work. This way seems
safe).
Most of the time $raw comes back empty.
Using Data::Dumper on %fdat, I get something like this when it works:
$VAR1 = {
'-file' => {
'Content-Disposition' => 'form-data; name="file"; filename="somefile.txt"',
'Content-Type' => 'text/plain'
},
'file' => bless( \*{'Fh::fh00001somefile.txt'}, 'Fh' )
};
When it fails, I get this instead:
$VAR1 = {
'-file' => undef,
'file' => bless( \*{'Fh::fh00001somefile.txt'}, 'Fh' )
};
It seems that the browser is at least doing the right thing, because the
CONTENT_LENGTH and CONTENT_TYPE environment variables seem to be set
correctly:
CONTENT_LENGTH = 98542
CONTENT_TYPE = multipart/form-data; boundary=---------------------------12726745371892987527108562749
Anyone seeing this? Where should be looking to find the solution?
Thanks,
Rob.
Re: [RESEND] Empty file uploads
Posted by Robert Norris <Ro...@its.monash.edu.au>.
All,
> > P.S. What version of CGI.pm do you have?
>
> 2.752.
On Gerald's advice, I upgraded CGI.pm to the latest version on CPAN
(3.07). This appears to have fixed the problem, though I'm not sure why.
Anyway, its in the archive now, so if anyone sees this problem in the
future, this might help.
Cheers,
Rob.
Re: [RESEND] Empty file uploads
Posted by Robert Norris <Ro...@its.monash.edu.au>.
On Fri, Mar 18, 2005 at 03:01:10PM +0100, Gerald Richter wrote:
> While the browser seems to send the file, it does not seem to encode it
> correctly, otherwise we should see something in -file.
I added code to dump $rec_req->content to a file so I could check it.
The file appears to be intact. Even if its not though, the MIME headers
are absolutely correct - there should be _something_ in -file.
> The only thing I see that is differnt with the form that I use is that you
> don't have the action attribute in your <form> tag
I don't usually set it, which makes the browser just submit back to the
current page. I never realised that action is required by the HTML spec.
I tried setting in, but it hasn't fixed the problem.
> P.S. What version of CGI.pm do you have?
2.752.
Rob.
RE: [RESEND] Empty file uploads
Posted by Gerald Richter <ri...@ecos.de>.
>
> When it fails, I get this instead:
>
>
> $VAR1 = {
> '-file' => undef,
> 'file' => bless( \*{'Fh::fh00001somefile.txt'}, 'Fh' )
> };
>
>
> It seems that the browser is at least doing the right thing,
> because the CONTENT_LENGTH and CONTENT_TYPE environment
> variables seem to be set
> correctly:
>
While the browser seems to send the file, it does not seem to encode it
correctly, otherwise we should see something in -file.
The only thing I see that is differnt with the form that I use is that you
don't have the action attribute in your <form> tag
Gerald
P.S. What version of CGI.pm do you have?
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org