perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Brewer <>
Subject [mp2] can't locate object method "upload" via package "Apache::RequestRec"
Date Sun, 07 Nov 2004 00:04:43 GMT

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/ line 135.\n

I've a library I'm writing,, 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;

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?



Report problems:
Mail list info:
List etiquette:

View raw message