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/01 00:53:46 UTC
Empty file uploads
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: Empty file uploads
Posted by Robert Norris <Ro...@its.monash.edu.au>.
On Mon, Feb 28, 2005 at 07:04:43PM -0500, Daniel wrote:
> I don't seem to have any problems with this. Perhaps you could try this
> method instead?
Saving a temporary file doesn't suit my application, but I did test this
just to see what would happen. Same problem.
BTW, I didn't mention that I'm using Embperl::Object. Not sure if it
will make a difference.
Rob.
Re: Empty file uploads
Posted by Daniel <em...@7thfire.com>.
Hi,
I'm using this syntax:
<FORM METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="IDPD_File" size=60>
</form>
my $buffer;
if (open FILE, "> $tmpFile") {
print FILE $buffer while read($$fdat{file}, $buffer, 32768);
close FILE;
}
I don't seem to have any problems with this. Perhaps you could try this
method instead?
db
On Tue, Mar 01, 2005 at 10:53:46AM +1100, Robert Norris wrote:
> 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.
--
"Those who would give up essential Liberty, to purchase a little temporary
Safety, deserve neither Liberty nor Safety." -- Benjamin Franklin
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Empty file uploads
Posted by Robert Norris <Ro...@its.monash.edu.au>.
On Thu, Mar 03, 2005 at 07:51:22AM +0100, Gerald Richter wrote:
> Please try to use the code Daniel posted instead of yours. Similars code
> works for me for years now without problems
As I said in a previous email, I tested this and it doesn't work most of
the time.
Rob.
RE: Empty file uploads
Posted by Gerald Richter <ri...@ecos.de>.
>
> Note the filename - its the same as the one I was using for
> my upload tests as described in my previous email. I must
> stress that this piece of code is entirely unrelated - it
> isn't even a form. However, it is running under the same set
> of Embperl objects that build the site, and is running out of
> the same mod_perl.
>
> It also isn't causing a problem - I've fixed the bug that
> made the compiler break, and all is well.
>
> My money is on some global variable that isn't being cleared
> properly. I wouldn't know where to start looking.
>
That filename might be from the fact that Perl thinks you are still about to
read from the file handle of the uploaded file. I don't think that's a
problem.
Please try to use the code Daniel posted instead of yours. Similars code
works for me for years now without problems
Gerald
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Empty file uploads
Posted by Robert Norris <Ro...@its.monash.edu.au>.
> Anyone seeing this? Where should be looking to find the solution?
Just FYI, while working on something else within the same
Embperl::Object tree today, I screwed up some code, so it failed to
compile. I got this in the Apache error log:
[Thu Mar 03 14:24:00 2005] [error] [2743]ERR: 24: Error in Perl code: syntax error at /net/apache2/htdocs/mail/quota/config.epl line 12, near "3389';\n$r->{'"\n\t(in cleanup) Bad name after ldap_basedn' at /net/apache2/htdocs/mail/quota/config.epl line 12, <fh00001somefile.txt>
line 1.
[Thu Mar 03 14:24:00 2005] [error] [2743]ERR: 24: Error in Perl code: \t(in cleanup) Unmatched ) before HERE mark in regex m/^/error/ ) << HERE { \n _ep_cp(17) ;\n#line 38 "/ at /net/apache2/htdocs/layout/header.epl line 38, <fh00001somefile.txt> line 1.
[Thu Mar 03 14:24:00 2005] [error] [2743]ERR: 24: Error in Perl code: \t(in cleanup) Unmatched ) before HERE mark in regex m/^/error/ ) << HERE { \n _ep_cp(17) ;\n#line 38 "/ at /net/apache2/htdocs/layout/header.epl line 38, <fh00001somefile.txt> line 1.
Note the filename - its the same as the one I was using for my upload
tests as described in my previous email. I must stress that this piece
of code is entirely unrelated - it isn't even a form. However, it is
running under the same set of Embperl objects that build the site, and
is running out of the same mod_perl.
It also isn't causing a problem - I've fixed the bug that made the
compiler break, and all is well.
My money is on some global variable that isn't being cleared properly. I
wouldn't know where to start looking.
Where to next?
Rob.