You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Raymond Wan <rw...@kuicr.kyoto-u.ac.jp> on 2007/06/10 15:44:45 UTC

"End of file found" error for file uploading

Hi all,

I'm trying to figure out how to handle file uploads from a user.  I am 
using Mason with mod_perl2 under Apache 2.x, but I have a feeling this 
has nothing to do with Mason as I saw a similar question in December 
2006 on this mailing list.  Yet, there wasn't a relevant solution as the 
problem then seemed to have been with CGI.pm, but I'm not using it.

I enable apreq2 and then tried this:

my $contents = '';
my $req = Apache2::Request -> new ($r);
my $upload = $req->upload ('foo');
my $size = $upload -> slurp($contents);

with a form using the "post" method and an enctype of "multipart/form-data".

In my browser, I am getting a single message: "End of file found".  That 
is, the single line.  Other print's that I had on the page for debugging 
are not printed.  There is nothing recorded in error.log and nothing in 
the request in access.log indicates something is wrong.

The culprit is actually the third line because if I remove the fourth 
line, the problem remains.  If I remove the third line, the page 
displays fine...

Any suggestions on what I am doing wrong or where I should look to 
figure out the problem?  Thanks in advance!

Ray




Re: "End of file found" error

Posted by Raymond Wan <rw...@kuicr.kyoto-u.ac.jp>.
Hi Joe,

Joe Schaefer wrote:
>> Anything here looks suspicious?
>>     
>
> Yes.  Your code behaves as if CGI.pm was being used by Mason instead
> of apreq.  When that happens, CGI.pm steals the post data, and
> apreq sees nothing but an "End of File" situation.
>
> If I were you, I'd double-check how you configured Mason to select
> apreq instead of CGI.pm.  That's probably where the bug lies.
>   

Thanks for the tip!  Yes, I finally found the problem.  Indeed, it was 
because of how I configured Mason -- by default, it uses CGI.pm...  No 
wonder the word "CGI" didn't appear in any of my configuration files 
when I was grepping...

Unrelated to modperl, but in case a Mason user sees the same problem as 
me, adding this line to httpd.conf will do it:

PerlSetVar MasonArgsMethod 'mod_perl'

Now, I can see the number of parameters sent and can access the uploaded 
file fine.  That's a lot of time spent for a single line...  :-)  Thanks 
for the help and the suggestion...that definitely helped me narrow 
things down!

Ray



Re: "End of file found" error

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Raymond Wan <rw...@kuicr.kyoto-u.ac.jp> writes:

> For some reason, I am doubting my own HTML skills...or perhaps I've
> been staring at this for so long, the screen is getting blurry :-) .
> Anything here looks suspicious?

Yes.  Your code behaves as if CGI.pm was being used by Mason instead
of apreq.  When that happens, CGI.pm steals the post data, and
apreq sees nothing but an "End of File" situation.

If I were you, I'd double-check how you configured Mason to select
apreq instead of CGI.pm.  That's probably where the bug lies.

-- 
Joe Schaefer


Re: "End of file found" error

Posted by Raymond Wan <rw...@kuicr.kyoto-u.ac.jp>.
Hi Joe,

Joe Schaefer wrote:
>> running on a test machine (i.e., the web server isn't live on the
>> Internet) so perhaps I didn't set it up correctly?
>>     
>
> I really don't know, it could be the parser is just misbehaving on your
> particular html form.  What you can do to further investigate is something like
> this:
>
>    my $upload = eval { $req->upload("foo") };
>    if ($@) {
>       $upload = $@->upload("foo"); # won't die this time
>    }
>    ...
>
> and try to see where the form data is getting lost.
>   

For some reason, I am doubting my own HTML skills...or perhaps I've been 
staring at this for so long, the screen is getting blurry :-) .  
Anything here looks suspicious?

test1.html:

<form action="http://localhost/~user/test2.html" method="post" 
enctype="multipart/form-data" name="mai nform">

<input type="file" name="filename" />
<input type="text" width="10" name="keyword" />
<button type="submit">Submit</button>
<button type="reset">Clear</button>
</form>


test2.html:

<%args>
$filename
$keyword
</%args>
<%perl>
print $filename, "<br />";
print $keyword, "<br />";

my $req = Apache2::Request -> new ($r);
my @params = $req -> param ();
print scalar (@params), "\n<br />\n";
</%perl>

<%
#my $upload = $req->upload ('filename');
%>

There's some Mason in there, but basically, both $filename and $keyword 
print out ok (well, the filename), so it doesn't seem like any part of 
the form is "lost".  "scalar (@params)" is 0, though...which makes me 
think I'm doing something wrong.  Shouldn't it be 2?  And of course, if 
I move the commented line up, I get the "End of file found" error...

As much as I'd like to be like other newbies and blame either apreq2 or 
the browser and say one of them is buggy :-) ...I'm more inclined to 
believe that since other people use it, it must be something that I'm 
doing wrong.  If I remove the file input, and just leave the text box, 
then I still get the error.  So, it isn't because of the file 
uploading...  (I've changed the Subject to reflect this...)

Perhaps it's what I'm doing with Mason?

Ray

PS:  I don't mean to put you on the spot, Joe, for replying to me 
initially (which I am thankful for!).  Of course, if anyone else can 
give me their ideas, I'd appreciate it, too!



Re: "End of file found" error for file uploading

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Raymond Wan <rw...@kuicr.kyoto-u.ac.jp> writes:

> apreq2 is version 2.08.4 on Debian stable (testing seems to have a
> 2.08.5...). 

Hmm, that's the latest version.  I don't think debian has applied any
local mods to the codebase.

> Any suggestions on how I can resolve the problem?  Could there be
> something wrong in the server set-up, etc.?  As I said, it's all
> running on a test machine (i.e., the web server isn't live on the
> Internet) so perhaps I didn't set it up correctly?

I really don't know, it could be the parser is just misbehaving on your
particular html form.  What you can do to further investigate is something like
this:

   my $upload = eval { $req->upload("foo") };
   if ($@) {
      $upload = $@->upload("foo"); # won't die this time
   }
   ...

and try to see where the form data is getting lost.


-- 
Joe Schaefer


Re: "End of file found" error for file uploading

Posted by Raymond Wan <rw...@kuicr.kyoto-u.ac.jp>.
Hi Joe,

Joe Schaefer wrote:
>> with a form using the "post" method and an enctype of
>> "multipart/form-data". 
>>
>> In my browser, I am getting a single message: "End of file found".
>> That is, the single line.
>>     
>
> What's happening is that $req->upload calls $req->body, and that is
> die'ing with the "End of file found" error.  What browser are you using,
> and what version of apreq?
>   

Oh!  I see.  After I read your message, I tried other browsers and while 
all browsers could be wrong, I got the same error.  First, I was using 
Iceweasel 2.0.0.3 and then I tried the Gnome Web Browser (Epiphany) 
2.14.3 and even Elinks 0.11.X, all running on Debian and the same 
machine that the server is on (I'm testing locally).

apreq2 is version 2.08.4 on Debian stable (testing seems to have a 
2.08.5...).

Any suggestions on how I can resolve the problem?  Could there be 
something wrong in the server set-up, etc.?  As I said, it's all running 
on a test machine (i.e., the web server isn't live on the Internet) so 
perhaps I didn't set it up correctly?

Thank you for your reply!

Ray



Re: "End of file found" error for file uploading

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Raymond Wan <rw...@kuicr.kyoto-u.ac.jp> writes:

> I enable apreq2 and then tried this:
>
> my $contents = '';
> my $req = Apache2::Request -> new ($r);
> my $upload = $req->upload ('foo');
> my $size = $upload -> slurp($contents);
>
> with a form using the "post" method and an enctype of
> "multipart/form-data". 
>
> In my browser, I am getting a single message: "End of file found".
> That is, the single line.

What's happening is that $req->upload calls $req->body, and that is
die'ing with the "End of file found" error.  What browser are you using,
and what version of apreq?

(The problem you're seeing is either a bug in apreq's mfd parser, 
or in what your browser is actually emitting).

-- 
Joe Schaefer