You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Pete Smith <pe...@popcornwebdesign.co.uk> on 2004/01/16 10:07:45 UTC
File uploads using Apache:;request in mod_perl2
Hi,
I am new to this list, but I have tried looking through the docs at CPAN and
googling for people with similar problems to no avail.
We have upgraded our server to apache2 + mod_perl2. I used to have a routine
that took a file upload from a multipart form and handed it as a stream to
Imager and Image::Size like so:
my $image_upload = $r->upload('image');
my $file_handle = $image_upload->fh();
read ($file_handle, my $full_image_data, (stat($file_handle))[7]);
my $imager = Imager->new();
$imager->open(data => $full_image_data, type => 'jpeg');
my ($width) = imgsize(\$full_image_data);
I now know that I could pass the file handle to Imager and Image::Size
instead of turning into a scalar stream, but that isn't the problem.
I have discovered that Apache::Request for mod_perl2 has changed the fh
method to bb, which apparently returns an APR::Brigade (object I presume)
instead of a file handle.
I have looked for documentation for APR::Brigade, but can find none. I have
no idea what it is!
Could somebody please point me in the right direction as to how I can
achieve the above in mod_perl2?
Thanks,
Pete
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
readdir producing NULL results with glicb 2.2
Posted by O'K Web Design <ok...@rogers.com>.
Hi
I have a problem with readdir returning no values when running with
mod_perl. I have seen the docs that suggest a rebuild of Perl will help,
which I have done. I also saw that there might be some issues with glicb
2.2 only with readdir. I do have a workaround developed but wondered if
anyone had any ideas before hacking my script. Mike
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Kevin Bosak <ke...@bosak.net>.
I don't know what you did, but it works now! Thank you so much for your
time.
Joe Schaefer wrote:
>
> Try replacing the apreq_xs_upload_link() function in
>
> glue/perl/xsbuilder/Apache/Request/Apache__Request.h
>
> with the following one; rebuild and install it. If this
> doesn't solve your problem, the next release should include more
> helpful diagnostics, but until then CGI.pm is always available.
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Kevin Bosak <ke...@bosak.net> writes:
> Thanks again for the help but still no luck.
> I set the TMPDIR environment variable manually and restarted apache
> but still can't get the upload file in my script and nothing's being
> written to the tmpdir. If there's anything else I can try please let
> me know but I may just end up having to use CGI.pm for uploads.
Try replacing the apreq_xs_upload_link() function in
glue/perl/xsbuilder/Apache/Request/Apache__Request.h
with the following one; rebuild and install it. If this
doesn't solve your problem, the next release should include more
helpful diagnostics, but until then CGI.pm is always available.
APR_INLINE
static XS(apreq_xs_upload_link)
{
dXSARGS;
MAGIC *mg;
void *env;
const char *name, *fname;
apr_bucket_brigade *bb;
apr_file_t *f;
if (items != 2 || !SvROK(ST(0)))
Perl_croak(aTHX_ "Usage: $upload->link($name)");
if (!(mg = mg_find(SvRV(ST(0)), PERL_MAGIC_ext)))
Perl_croak(aTHX_ "$upload->link($name): can't find env");
env = mg->mg_ptr;
bb = apreq_xs_rv2param(ST(0))->bb;
name = SvPV_nolen(ST(1));
f = apreq_brigade_spoolfile(bb);
if (f == NULL) {
apr_off_t len;
apr_status_t s;
const apr_int32_t flags = APR_CREATE | APR_EXCL | APR_WRITE |
APR_READ | APR_BINARY | APR_BUFFERED;
s = apr_file_open(&f, name, flags,
APR_OS_DEFAULT,
apreq_env_pool(env));
if (s != APR_SUCCESS ||
apreq_brigade_fwrite(f, &len, bb) != APR_SUCCESS)
XSRETURN_UNDEF;
XSRETURN_YES;
}
if (apr_file_name_get(&fname, f) != APR_SUCCESS)
XSRETURN_UNDEF;
if (PerlLIO_link(fname, name) >= 0)
XSRETURN_YES;
else {
apr_status_t s = apr_file_copy(fname, name,
APR_OS_DEFAULT,
apreq_env_pool(env));
if (s == APR_SUCCESS)
XSRETURN_YES;
}
XSRETURN_UNDEF;
}
--
Joe Schaefer
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Kevin Bosak <ke...@bosak.net>.
Thanks again for the help but still no luck.
I set the TMPDIR environment variable manually and restarted apache but
still can't get the upload file in my script and nothing's being written
to the tmpdir. If there's anything else I can try please let me know
but I may just end up having to use CGI.pm for uploads.
Joe Schaefer wrote:
> At the moment, grepping Mason's source files for TEMP_DIR or TMPDIR is
> probably the only solution. I don't think the current Apache::Request
> for mp2 exposes enough of the C API to be of any help to you.
>
> If you're using glibc, the sledgehammer approach is to have the
> sysadmin set/export the TMPDIR environment variable prior to server
> startup, ie.
>
> % TMPDIR=/path/to/my/tmpdir apachectl restart
>
> This will override any TEMP_DIR settings coming from calls to
> Apache::Request::new().
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Kevin Bosak <ke...@bosak.net> writes:
> Thanks for the advice.
> I checked and $upload->link does indeed return false. I'm guessing
> it's because of something with TEMP_DIR you said, but my lack of
> knowledge is keeping me from getting this resolved. How do I
> determine what TEMP_DIR has been set to?
At the moment, grepping Mason's source files for TEMP_DIR or TMPDIR is
probably the only solution. I don't think the current Apache::Request
for mp2 exposes enough of the C API to be of any help to you.
> I'm using Mason with ApacheHandler2 that I believe sets up the
> Apache::Request object but I'm still a little unclear on how
> everything fits together. I could definitely use another "nudge" in
> the right direction.
If you're using glibc, the sledgehammer approach is to have the
sysadmin set/export the TMPDIR environment variable prior to server
startup, ie.
% TMPDIR=/path/to/my/tmpdir apachectl restart
This will override any TEMP_DIR settings coming from calls to
Apache::Request::new().
btw- I'm planning to $upload->link so that it will handle the
cross-device situation more gracefully (by making a full copy
of the tempfile should the internal PerlLIO_link fail).
--
Joe Schaefer
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Kevin Bosak <ke...@bosak.net>.
Thanks for the advice.
I checked and $upload->link does indeed return false. I'm guessing it's
because of something with TEMP_DIR you said, but my lack of knowledge is
keeping me from getting this resolved. How do I determine what TEMP_DIR
has been set to? I'm using Mason with ApacheHandler2 that I believe
sets up the Apache::Request object but I'm still a little unclear on how
everything fits together. I could definitely use another "nudge" in the
right direction.
Joe Schaefer wrote:
>
>
> Three things to check:
>
> 1) be sure $filename is valid (it really should be marked as tainted),
> 2) be sure "/path/to/local/$filename" is on the same device
> (filesystem) as your temporary directory (see the docs for
> Apache::Request::new regarding TEMP_DIR).
> 3) check the return value of $upload->link, if it's false (undef) then
> there was a problem- usually the trouble is caused by one of the above.
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Kevin Bosak <ke...@bosak.net> writes:
> I can get the file's name but the upload
> is simply not getting linked/saved. I'm sure it's probably something
> I'm doing wrong, but I don't know what. Here's the relevant lines
> from my code:
>
> my $upload = $r->upload('file');
> my $filename = $upload->filename;
> $upload->link("/path/to/local/$filename");
>
> Is there something I can do to troubleshoot this?
Three things to check:
1) be sure $filename is valid (it really should be marked as tainted),
2) be sure "/path/to/local/$filename" is on the same device
(filesystem) as your temporary directory (see the docs for
Apache::Request::new regarding TEMP_DIR).
3) check the return value of $upload->link, if it's false (undef) then
there was a problem- usually the trouble is caused by one of the above.
--
Joe Schaefer
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Kevin Bosak <ke...@bosak.net>.
Thanks for the reply! But unfortunately I'm not having any luck with
link either. I'm using Mason 1.25 which isn't giving any errors and
there are no errors showing up in the apache logs. I can get the file's
name but the upload is simply not getting linked/saved. I'm sure it's
probably something I'm doing wrong, but I don't know what. Here's the
relevant lines from my code:
my $upload = $r->upload('file');
my $filename = $upload->filename;
$upload->link("/path/to/local/$filename");
Is there something I can do to troubleshoot this?
Any help will be greatly appreciated.
And FYI, I'm using libapreq2-2.02_02-dev.
Joe Schaefer wrote:
> Kevin Bosak <ke...@bosak.net> writes:
>
>
>>I too am having issues with file uploads using mod_perl2. I've gotten
>>the beta of Apache::Request but it looks like from this thread that
>>there's not yet a way to retrieve the uploaded file. Is this true?
>
>
> No, it's not true at all. If you don't need to read the contents of the
> upload, but just need to store it in a file somewhere, use
> $upload->link("/path/to/local/file"). If you do need to read the
> contents, use the APR::Brigade API on $upload->bb. A future version
> of Apache::Request may have include convenience methods (like slurp(),
> etc.), but you can certainly get at the uploaded file using the current
> version.
>
> The brigade API is a big performance-win for libapreq2, since it allows
> us to use a zero-copy design on file uploads until the file gets too
> big to store in memory. The size limit is currently 256K, but the size
> will be configurable in future versions.
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Kevin Bosak <ke...@bosak.net> writes:
> I too am having issues with file uploads using mod_perl2. I've gotten
> the beta of Apache::Request but it looks like from this thread that
> there's not yet a way to retrieve the uploaded file. Is this true?
No, it's not true at all. If you don't need to read the contents of the
upload, but just need to store it in a file somewhere, use
$upload->link("/path/to/local/file"). If you do need to read the
contents, use the APR::Brigade API on $upload->bb. A future version
of Apache::Request may have include convenience methods (like slurp(),
etc.), but you can certainly get at the uploaded file using the current
version.
The brigade API is a big performance-win for libapreq2, since it allows
us to use a zero-copy design on file uploads until the file gets too
big to store in memory. The size limit is currently 256K, but the size
will be configurable in future versions.
--
Joe Schaefer
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Kevin Bosak <ke...@bosak.net>.
I too am having issues with file uploads using mod_perl2. I've gotten
the beta of Apache::Request but it looks like from this thread that
there's not yet a way to retrieve the uploaded file. Is this true?
Pete Smith wrote:
> Hi,
>
> I am new to this list, but I have tried looking through the docs at CPAN and
> googling for people with similar problems to no avail.
>
> We have upgraded our server to apache2 + mod_perl2. I used to have a routine
> that took a file upload from a multipart form and handed it as a stream to
> Imager and Image::Size like so:
>
>
> my $image_upload = $r->upload('image');
> my $file_handle = $image_upload->fh();
>
> read ($file_handle, my $full_image_data, (stat($file_handle))[7]);
>
> my $imager = Imager->new();
>
> $imager->open(data => $full_image_data, type => 'jpeg');
> my ($width) = imgsize(\$full_image_data);
>
>
> I now know that I could pass the file handle to Imager and Image::Size
> instead of turning into a scalar stream, but that isn't the problem.
>
> I have discovered that Apache::Request for mod_perl2 has changed the fh
> method to bb, which apparently returns an APR::Brigade (object I presume)
> instead of a file handle.
>
> I have looked for documentation for APR::Brigade, but can find none. I have
> no idea what it is!
>
> Could somebody please point me in the right direction as to how I can
> achieve the above in mod_perl2?
>
> Thanks,
> Pete
>
>
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Geoffrey Young <ge...@modperlcookbook.org> writes:
> Joe Schaefer wrote:
> > my $upload_data = $req->upload('file')->bb->flatten;
>
> oooh, nice. I can definitely see that being a useful idiom.
Not sure if it'd be better for flatten to take $upload_data as
an argument and return a status code instead, but I'll happily
leave that decision for the implementer :-).
--
Joe Schaefer
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Joe Schaefer wrote:
> Geoffrey Young <ge...@modperlcookbook.org> writes:
>
> [...]
>
>
>>I'm not as familiar with brigades as I should be, but does
>>it save you the iteration process or is it just a substitute for
>>reading to a buffer?
>
>
> It'd save you the iteration process (it's an APR::Brigade method,
> not APR::Bucket), but would not destroy the buckets within the
> brigade (hmm, does APR::Brigade have a DESTROY method?).
>
> The advantage here is you'd be able to accomplish this
> in one or two lines of perl, ie.
>
> my $upload_data = $req->upload('file')->bb->flatten;
oooh, nice. I can definitely see that being a useful idiom.
let's see about opening it up.
--Geoff
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
> [...]
>
>
>>You need the filehandle only if you use the temp file. In which case
>>bbs are irrelevant. If you use slurp then there is are no
>>filehandles. I think these are orthogonal.
>
>
> Agreed- my earlier +1 was for both adding a slurp() method and
> marking the output as tainted.
Understood.
So since we are designing a new interface. Would it make sense to have slurp()
accept an optional argument limiting the size of the data it's going to slurp?
I mean the MAX_POST_DATA (or whatever it is) limit is all good, but since for
big data we mainly use temp files MAX_POST_DATA, we may want to say
upload->slurp(2**14) or die "the input is too big";
actually, I'm having another idea on slurp. Since it smells too read()-like.
One could have an APREQ::PerlIO layer and having upload return that filehandle
opened through that layer (like APR::PerlIO or Apache::PerlIO do). Now you
could transparently do temp files or inmemory uploads, giving the user the
good old read() API. You can even support seek/tell to make things fancier. Of
course this will require perl 5.8 compiled with perlio.
If you have that in place, you need no slurp. You do 'local $/ + read' and you
get slurp. Or may be it's too much work when implementing slurp should be a
few lines of C code ;)
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
[...]
> You need the filehandle only if you use the temp file. In which case
> bbs are irrelevant. If you use slurp then there is are no
> filehandles. I think these are orthogonal.
Agreed- my earlier +1 was for both adding a slurp() method and
marking the output as tainted.
--
Joe Schaefer
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
[...]
>>I'm not against adding the perl glue for APR::Brigade::flatten, quite
>>on the opposite I'm all for it. All I was saying is that users don't
>>need to know about the existance of APR::Brigade at all. Not only
>>because it's an unnecessary information to 99.9% of users out there,
>>but also because if tomorrow you decide to change the internal
>>implementation you will be now stuck with dependancy on that flatten
>>call.
>
>
> My viewpoint on brigades has changed over the last year- they're
> so much more flexible than filehandles are. I now see upload->bb()
> as an abstraction of upload->fh().
You need the filehandle only if you use the temp file. In which case bbs are
irrelevant. If you use slurp then there is are no filehandles. I think these
are orthogonal.
> Since libapreq2 is a pure apr
> application, I don't think the brigade APIs are ever coming out of
> apreq2. Increasing the apr-dependence doesn't seem harmful to me.
Yes, but reread this para. It took you quite time to grok bbs and appreciate
them. It's good to appreciate and know how they work when you need more
flexibility, better performance in certain cases and you don't just want to
have this upload script working.
>>BTW, please remember that if and when you add slurp it should make
>>the slurped data tainted under -T/-t. Thanks Joe.
>
>
> +1. Should we mark normal params tainted as well?
CGI.pm uses normal read() to gets its data, which means that all data it
returns via params is tainted. (but please double check). So I think the
answer is yes.
I'm not sure whether mp1's and mp2's read return the data tainted. Can someone
give it a test? I think mp2 doesn't and it should, something to look at.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
>
> [...]
>
>
>>It doesn't sound like a good idea. Users ain't need to mess with
>>bucket brigades, unless they really want to. If the upload is always
>>going through the temp file, why making things complex for the users?
>
>
> Exactly because it is NOT always going through a temp file.
> Just look further upthread- this particular user doesn't
> even *want* a temp file, just the data. Why should he need
> to make all those "open/read/write/close file" system calls
> if he doesn't need them?
No reason to.
>>In any case it's the best to hide the internals behind an API,
>>so you can do:
>>
>>my $upload_data = $req->upload('file')->slurp;
>>
>>and inside slurp you have the C API to do anything you need. How
>>does that sound?
>
>
> That's a possibility, but I fail to see its advantage over
> APR::Brigade exposing flatten(). It is part of the C API
> after all, eh? Why shouldn't perl programmers have access
> to it?
I'm not against adding the perl glue for APR::Brigade::flatten, quite on the
opposite I'm all for it. All I was saying is that users don't need to know
about the existance of APR::Brigade at all. Not only because it's an
unnecessary information to 99.9% of users out there, but also because if
tomorrow you decide to change the internal implementation you will be now
stuck with dependancy on that flatten call. Hiding the details behind the
scenes sounds like the right thing to me, but you know that already ;)
BTW, please remember that if and when you add slurp it should make the slurped
data tainted under -T/-t. Thanks Joe.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
[...]
> It doesn't sound like a good idea. Users ain't need to mess with
> bucket brigades, unless they really want to. If the upload is always
> going through the temp file, why making things complex for the users?
Exactly because it is NOT always going through a temp file.
Just look further upthread- this particular user doesn't
even *want* a temp file, just the data. Why should he need
to make all those "open/read/write/close file" system calls
if he doesn't need them?
> In any case it's the best to hide the internals behind an API,
> so you can do:
>
> my $upload_data = $req->upload('file')->slurp;
>
> and inside slurp you have the C API to do anything you need. How
> does that sound?
That's a possibility, but I fail to see its advantage over
APR::Brigade exposing flatten(). It is part of the C API
after all, eh? Why shouldn't perl programmers have access
to it?
--
Joe Schaefer
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Geoffrey Young <ge...@modperlcookbook.org> writes:
>
> [...]
>
>
>>I'm not as familiar with brigades as I should be, but does
>>it save you the iteration process or is it just a substitute for
>>reading to a buffer?
>
>
> It'd save you the iteration process (it's an APR::Brigade method,
> not APR::Bucket), but would not destroy the buckets within the
> brigade (hmm, does APR::Brigade have a DESTROY method?).
>
> The advantage here is you'd be able to accomplish this
> in one or two lines of perl, ie.
>
> my $upload_data = $req->upload('file')->bb->flatten;
It doesn't sound like a good idea. Users ain't need to mess with bucket
brigades, unless they really want to. If the upload is always going through
the temp file, why making things complex for the users?
In any case it's the best to hide the internals behind an API, so you can do:
my $upload_data = $req->upload('file')->slurp;
and inside slurp you have the C API to do anything you need. How does that sound?
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Geoffrey Young <ge...@modperlcookbook.org> writes:
[...]
> I'm not as familiar with brigades as I should be, but does
> it save you the iteration process or is it just a substitute for
> reading to a buffer?
It'd save you the iteration process (it's an APR::Brigade method,
not APR::Bucket), but would not destroy the buckets within the
brigade (hmm, does APR::Brigade have a DESTROY method?).
The advantage here is you'd be able to accomplish this
in one or two lines of perl, ie.
my $upload_data = $req->upload('file')->bb->flatten;
--
Joe Schaefer
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> In your mp1 code, you are simply slurping the upload into
> $full_image_data; with apreq2 you can do that with a bucket
> brigade via
>
> my $bb = $req->upload('image')->bb;
> my $full_image_data = "";
>
> while (my $b = $bb->first) {
> $b->read(my $buffer);
> $full_image_data .= $buffer;
> $b->remove;
> }
>
> I'm sure there are better ways to use the brigade API
> though.
that's pretty much the only way I've seen it used, but stas might have other
examples up his sleeve.
I did think that $b->remove() was still problematic though
> The C API for brigades has a "flatten" function-
> does anyone know if mp2 has glue for that yet?
apr_brigade_flatten and apr_brigade_pflatten are currently not open, though
they are marked as "unclassified" which I take to mean that doug never
decided whether to make them available or not.
I'm not as familiar with brigades as I should be, but does it save you the
iteration process or is it just a substitute for reading to a buffer?
--Geoff
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Clayton Cottingham <dr...@telus.net>.
i just figured something like this out on perlmonks.org:
http://www.perlmonks.org/index.pl?node_id=320770
On Fri, 2004-01-16 at 11:02, Joe Schaefer wrote:
> "Pete Smith" <pe...@popcornwebdesign.co.uk> writes:
>
> [...]
>
> > my $image_upload = $r->upload('image');
> > my $file_handle = $image_upload->fh();
> >
> > read ($file_handle, my $full_image_data, (stat($file_handle))[7]);
> >
> > my $imager = Imager->new();
> >
> > $imager->open(data => $full_image_data, type => 'jpeg');
> > my ($width) = imgsize(\$full_image_data);
> >
> >
> > I now know that I could pass the file handle to Imager and Image::Size
> > instead of turning into a scalar stream, but that isn't the problem.
> >
> > I have discovered that Apache::Request for mod_perl2 has changed the
> > fh method to bb, which apparently returns an APR::Brigade (object I
> > presume) instead of a file handle.
> >
> > I have looked for documentation for APR::Brigade, but can find none. I
> > have no idea what it is!
>
> APR::Brigade is, well, the perl glue for libaprutil's apr_brigade_t C struct.
> Along with buckets, they are used throughout the filter api, both in
> apache2 and mp2 (collectively referred to as "bucket brigades").
>
> > Could somebody please point me in the right direction as to how I can
> > achieve the above in mod_perl2?
>
> In your mp1 code, you are simply slurping the upload into
> $full_image_data; with apreq2 you can do that with a bucket
> brigade via
>
> my $bb = $req->upload('image')->bb;
> my $full_image_data = "";
>
> while (my $b = $bb->first) {
> $b->read(my $buffer);
> $full_image_data .= $buffer;
> $b->remove;
> }
>
> I'm sure there are better ways to use the brigade API
> though. The C API for brigades has a "flatten" function-
> does anyone know if mp2 has glue for that yet?
>
> --
> Joe Schaefer
--
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: File uploads using Apache:;request in mod_perl2
Posted by Pete Smith <pe...@popcornwebdesign.co.uk>.
> In your mp1 code, you are simply slurping the upload into
> $full_image_data; with apreq2 you can do that with a bucket
> brigade via
>
> my $bb = $req->upload('image')->bb;
> my $full_image_data = "";
>
> while (my $b = $bb->first) {
> $b->read(my $buffer);
> $full_image_data .= $buffer;
> $b->remove;
> }
Thanks for your help, but I get 'Can't locate object method "first" via
package "APR::Brigade"' with the above.
I also get ''Can't locate object method "fh" via package "Apache::Request"'
if I follow Stas Bekman's advice and install apreq2, which I'm sure I've
done successfully.
Do you have any advice on how I can make sure I have apreq2 installed
correctly? I'm beginning to think it isn't installed/isn't loading properly
(it's a DSO).
Thanks,
Pete
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Stas Bekman <st...@stason.org>.
semuel wrote:
> Hello There.
>
> No, this was changed to Apache::RequestRec and friends.
> See http://perl.apache.org/docs/2.0/api/Apache/RequestRec.html
Not really. Apache::RequestRec and Apache::Request are two different things.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: File uploads using Apache:;request in mod_perl2
Posted by semuel <se...@semuel.co.il>.
Hello There.
Oh, and how could I forget. At the mason's wiki,
There is a live discussion about it.
http://www.masonhq.com/wiki/null?ApacheModPerl2
In general, I don't think that mason works well with Apache2.
And here is the formal announcement:
http://www.masonhq.com/docs/faq/#can_i_use_mason_with_mod_perl_1_
Have fun.
-----Original Message-----
From: semuel [mailto:semuel@semuel.co.il]
Sent: Monday, January 19, 2004 7:20 PM
To: 'Pete Smith'
Cc: modperl@perl.apache.org
Subject: RE: File uploads using Apache:;request in mod_perl2
Hello There.
No, this was changed to Apache::RequestRec and friends.
See http://perl.apache.org/docs/2.0/api/Apache/RequestRec.html
Semuel.
-----Original Message-----
From: Pete Smith [mailto:pete@popcornwebdesign.co.uk]
Sent: Monday, January 19, 2004 6:07 PM
To: 'Joe Schaefer'
Cc: modperl@perl.apache.org
Subject: RE: File uploads using Apache:;request in mod_perl2
Sorry, I forgot to mention this too.
I am defining $r as the request object, like in mod_perl1:
my $r = Apache::Request->new(shift,
TEMP_DIR => '/tmp/mason',
);
Is this correct in mod_perl2? I'm sorry, but I'm not terribly clued up on
mod_perl2 yet...
Thanks,
Pete
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: File uploads using Apache:;request in mod_perl2
Posted by semuel <se...@semuel.co.il>.
Hello There.
No, this was changed to Apache::RequestRec and friends.
See http://perl.apache.org/docs/2.0/api/Apache/RequestRec.html
Semuel.
-----Original Message-----
From: Pete Smith [mailto:pete@popcornwebdesign.co.uk]
Sent: Monday, January 19, 2004 6:07 PM
To: 'Joe Schaefer'
Cc: modperl@perl.apache.org
Subject: RE: File uploads using Apache:;request in mod_perl2
Sorry, I forgot to mention this too.
I am defining $r as the request object, like in mod_perl1:
my $r = Apache::Request->new(shift,
TEMP_DIR => '/tmp/mason',
);
Is this correct in mod_perl2? I'm sorry, but I'm not terribly clued up on
mod_perl2 yet...
Thanks,
Pete
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: File uploads using Apache:;request in mod_perl2
Posted by Pete Smith <pe...@popcornwebdesign.co.uk>.
Sorry, I forgot to mention this too.
I am defining $r as the request object, like in mod_perl1:
my $r = Apache::Request->new(shift,
TEMP_DIR => '/tmp/mason',
);
Is this correct in mod_perl2? I'm sorry, but I'm not terribly clued up on
mod_perl2 yet...
Thanks,
Pete
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
"Pete Smith" <pe...@popcornwebdesign.co.uk> writes:
[...]
> my $image_upload = $r->upload('image');
> my $file_handle = $image_upload->fh();
>
> read ($file_handle, my $full_image_data, (stat($file_handle))[7]);
>
> my $imager = Imager->new();
>
> $imager->open(data => $full_image_data, type => 'jpeg');
> my ($width) = imgsize(\$full_image_data);
>
>
> I now know that I could pass the file handle to Imager and Image::Size
> instead of turning into a scalar stream, but that isn't the problem.
>
> I have discovered that Apache::Request for mod_perl2 has changed the
> fh method to bb, which apparently returns an APR::Brigade (object I
> presume) instead of a file handle.
>
> I have looked for documentation for APR::Brigade, but can find none. I
> have no idea what it is!
APR::Brigade is, well, the perl glue for libaprutil's apr_brigade_t C struct.
Along with buckets, they are used throughout the filter api, both in
apache2 and mp2 (collectively referred to as "bucket brigades").
> Could somebody please point me in the right direction as to how I can
> achieve the above in mod_perl2?
In your mp1 code, you are simply slurping the upload into
$full_image_data; with apreq2 you can do that with a bucket
brigade via
my $bb = $req->upload('image')->bb;
my $full_image_data = "";
while (my $b = $bb->first) {
$b->read(my $buffer);
$full_image_data .= $buffer;
$b->remove;
}
I'm sure there are better ways to use the brigade API
though. The C API for brigades has a "flatten" function-
does anyone know if mp2 has glue for that yet?
--
Joe Schaefer
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: File uploads using Apache:;request in mod_perl2
Posted by Pete Smith <pe...@popcornwebdesign.co.uk>.
> no, no, you have confused something. You need a new version of
> Apache::Request
> which is still in beta. Please take a look at:
> http://httpd.apache.org/apreq/
> Also please notice that it has its own mailing list if you have any
> questions.
Thanks for your help. I've installed it, and Apache seems to load it in OK
as a module. However my code still complains:
Can't locate object method "fh" via package "Apache::Upload"
I'm still not completely au fait with mod_perl, so please forgive my
ignorance, but I cannot find source or documentation for Apache::Upload. I
presume it's some sort of sub class of Apache::Request, which I believe
libapreq2-2.02 installs (I used the Makefile.PL way of configuring).
Thanks,
Pete
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: File uploads using Apache:;request in mod_perl2
Posted by Stas Bekman <st...@stason.org>.
Pete Smith wrote:
> Hi,
>
> I am new to this list, but I have tried looking through the docs at CPAN and
> googling for people with similar problems to no avail.
>
> We have upgraded our server to apache2 + mod_perl2. I used to have a routine
> that took a file upload from a multipart form and handed it as a stream to
> Imager and Image::Size like so:
[...]
> I have discovered that Apache::Request for mod_perl2 has changed the fh
> method to bb, which apparently returns an APR::Brigade (object I presume)
> instead of a file handle.
no, no, you have confused something. You need a new version of Apache::Request
which is still in beta. Please take a look at: http://httpd.apache.org/apreq/
Also please notice that it has its own mailing list if you have any questions.
I guess we should add a note to the compat doc:
http://perl.apache.org/docs/2.0/user/porting/compat.html
Alternatively you could use a slower CGI.pm for uploads till libapreq2 is
released.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html