You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Carl Brewer <ca...@bl.echidna.id.au> on 2004/11/07 01:04:43 UTC
[mp2] can't locate object method "upload" via package "Apache::RequestRec"
Forgive my poor perl and understanding of how this works!
I'm trying to grab images from a form, using libapreq2,
and I'm seeing this error :
[Sun Nov 07 10:52:34 2004] [error] Can't locate object method "upload"
via package "Apache::RequestRec" at /home/benfab/lib/BF.pm line 135.\n
I've a library I'm writing, BF.pm, that has the following two
subroutines in it :
sub hash_post {
# returns a hash of all the POST values
use Apache::Request;
use Apache::Upload;
my ($r) = shift;
my %rethash = {};
my $req = Apache::Request->new($r);
my @param_names = $req->param;
foreach my $value (@param_names) {
$rethash{$value} = $req->param($value);
}
return %rethash;
}
sub get_uploaded_image {
my ($name, $max_size, $r) = @_;
use Apache::Upload;
my $upload = $r->upload($name);
print STDERR $upload->filename();
}
They're pretty crude, but hash_post does what I need (any suggestions
for improvemend gladly accepted!). I'm working on the
get_uploaded_image() at the moment (as you can see, it doesn't do
anything yet!)
I've declared $r in my calling script, and I'm not sure if I
need to declare it again in the subroutines?
The calling script looks like this :
my $r = Apache->request;
$r->content_type("text/html");
use lib qw(/home/benfab/lib);
use BF;
use Template;
use Data::Dumper;
use strict;
.
.
.
my %posted_data = BF::hash_post($r);
my $upload = BF::get_uploaded_image("small_image",
$BF::small_image_size, $r);
If I change my subroutine to this :
sub get_uploaded_image {
my ($name, $max_size, $r) = @_;
use Apache::Upload;
my $req = Apache::Request->new($r);
my $upload = $req->upload($name);
print STDERR $upload->filename();
}
It starts to work, but I don't understand why I need to declare $req
again here? I want to keep my form parsing image stuff seperate,
as not all my pages will have images to load, am I doing this the
'best' way?
thanks!
Carl
--
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: [mp2] can't locate object method "upload" via package "Apache::RequestRec"
Posted by Tom Schindl <to...@gmx.at>.
Carl Brewer wrote:
> Tom Schindl wrote:
>
>> Carl Brewer wrote:
>>
>>>
>>>
>>> sub get_uploaded_image {
>>> my ($name, $max_size, $r) = @_;
>>>
>>> use Apache::Upload;
>>>
>> my $req = Apache::Request->new($r);
Apache::Request->instance($r)
just use Apache::Request->instance($r) and you're save but you
definately need to do that or simply pass on the created
Apache::Request-Object to you subroutine.
------------------------8<------------------------
I think that you and not a small number of other people have a problem
to see the difference between Apache::Request and Apache::RequestRec
they're both not the same.
Apache::RequestRec:
===================
"simply" wrapps the inter apache request-record to be accessible by
perl-modules. Docs at perl.apache.org
libapreq:
=========
is at it's heart a C library to deal easily with HTTP-Requests e.g. read
out form-data, ... . It has a mod_perl-binding named Apache::Request but
the whole lib can also be used by any other C-Module.
The already mentionned perl-Binding Apache::Request of libapreq is also
a derived from Apache::RequestRec and that's why it also has all methods.
------------------------8<------------------------
Tom
>> my $upload = $req->upload($name);
>
>
> I've got that in my subroutine and it works, but I'm concerned
> that I'm dipping into the buckets too much? Is it safe to
> call on $r more than once per form submission? I'm
> already runnign the new request() in a subroutine I call
> before I call the Upload one.
>
> thanks again,
>
> Carl
>
--
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: [mp2] can't locate object method "upload" via package "Apache::RequestRec"
Posted by Carl Brewer <ca...@bl.echidna.id.au>.
Tom Schindl wrote:
> Carl Brewer wrote:
>
>>
>>
>> sub get_uploaded_image {
>> my ($name, $max_size, $r) = @_;
>>
>> use Apache::Upload;
>>
> my $req = Apache::Request->new($r);
> my $upload = $req->upload($name);
I've got that in my subroutine and it works, but I'm concerned
that I'm dipping into the buckets too much? Is it safe to
call on $r more than once per form submission? I'm
already runnign the new request() in a subroutine I call
before I call the Upload one.
thanks again,
Carl
--
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: [mp2] can't locate object method "upload" via package "Apache::RequestRec"
Posted by Tom Schindl <to...@gmx.at>.
Carl Brewer wrote:
>
>
> sub get_uploaded_image {
> my ($name, $max_size, $r) = @_;
>
> use Apache::Upload;
>
my $req = Apache::Request->new($r);
my $upload = $req->upload($name);
> my $upload = $r->upload($name);
> print STDERR $upload->filename();
> }
>
>
>
> They're pretty crude, but hash_post does what I need (any suggestions
> for improvemend gladly accepted!). I'm working on the
> get_uploaded_image() at the moment (as you can see, it doesn't do
> anything yet!)
>
> I've declared $r in my calling script, and I'm not sure if I
> need to declare it again in the subroutines?
>
> The calling script looks like this :
>
> my $r = Apache->request;
> $r->content_type("text/html");
>
> use lib qw(/home/benfab/lib);
>
> use BF;
> use Template;
> use Data::Dumper;
> use strict;
>
> .
> .
> .
> my %posted_data = BF::hash_post($r);
> my $upload = BF::get_uploaded_image("small_image",
> $BF::small_image_size, $r);
>
>
>
> If I change my subroutine to this :
>
> sub get_uploaded_image {
> my ($name, $max_size, $r) = @_;
>
> use Apache::Upload;
>
> my $req = Apache::Request->new($r);
> my $upload = $req->upload($name);
> print STDERR $upload->filename();
> }
>
>
> It starts to work, but I don't understand why I need to declare $req
> again here? I want to keep my form parsing image stuff seperate,
> as not all my pages will have images to load, am I doing this the
> 'best' way?
>
> thanks!
>
> Carl
>
>
>
>
>
>
>
>
>
>
>
--
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