Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Catalyst::Request::Upload inside-out-object weirdness

by ikegami (Pope)
on Mar 26, 2010 at 15:01 UTC ( #831168=note: print w/ replies, xml ) Need Help??


in reply to Catalyst::Request::Upload inside-out-object weirdness

That kind of error occurs when one does

my %hash = ( 'w', x => $x, y => $y, z => $z, );
or
my %hash = ( w => w(), # Returns <1 or >1 elements x => $x, y => $y, z => $z, );

If so, it should give a "Odd number of elements in hash assignment" warning.

In this case, the following was assigned to the hash:

( size => 374205, \ or vice-versa type => "image/jpeg", / "charset=utf-8; Content-Transfer-Encoding: binary", XXX headers => $headers, tempname => "/tmp/5xSW7Swasp", filename => "aaa.jpg", )


Comment on Re: Catalyst::Request::Upload inside-out-object weirdness
Select or Download Code
Replies are listed 'Best First'.
Re^2: Catalyst::Request::Upload inside-out-object weirdness
by andye (Curate) on Mar 26, 2010 at 15:05 UTC
    yes - that's what i suspect is happening somewhere inside catalyst - and i do get that warning - here's more (earlier) console output from the server

    You can connect to your server at http://fishbone.local:3000 Use of uninitialized value in list assignment at /Library/Perl/5.8.6/C +atalyst/Engine/HTTP.pm line 371. Use of uninitialized value in list assignment at /Library/Perl/5.8.6/C +atalyst/Engine/HTTP.pm line 371. Odd number of elements in anonymous hash at generated method (unknown +origin) line 8. Use of uninitialized value in concatenation (.) or string at /Users/an +dye/PhotoApp/script/../lib/PhotoApp/Controller/Root.pm line 93. Use of uninitialized value in link at /Library/Perl/5.8.6/Catalyst/Req +uest/Upload.pm line 120. Use of uninitialized value in string eq at /System/Library/Perl/5.8.6/ +File/Copy.pm line 76. Use of uninitialized value in stat at /System/Library/Perl/5.8.6/File/ +Copy.pm line 82. Use of uninitialized value in -d at /System/Library/Perl/5.8.6/File/Co +py.pm line 91. Use of uninitialized value in -e at /Library/Perl/5.8.6/Catalyst/Engin +e.pm line 317.

    after looking at the docs some more, I'm now doing this:

    for my $field ( $c->req->upload ) { $c->log->warn("field is $field"); my $upload = $c->req->upload($field); my $filename = $upload->filename; my $target = $absGalleryPath . $filename; unless ( $upload->link_to($target) || $upload->copy_to($target +) ) { die( "Failed to copy '$filename' to '$target': $!" ); } }

    as per the cookbook, but still no joy.

      Why are you posting that snippet? You don't assign to any hashes in it
        Right. I don't assign the hash. It happens inside Catalyst.

        Looking at the source, it looks like it happens in Catalyst::Engine::prepare_uploads, which reads

        sub prepare_uploads { my ( $self, $c ) = @_; my $request = $c->request; return unless $request->_body; my $uploads = $request->_body->upload; my $parameters = $request->parameters; foreach my $name (keys %$uploads) { my $files = $uploads->{$name}; my @uploads; for my $upload (ref $files eq 'ARRAY' ? @$files : ($files)) { my $headers = HTTP::Headers->new( %{ $upload->{headers} } +); my $u = Catalyst::Request::Upload->new ( size => $upload->{size}, type => $headers->content_type, headers => $headers, tempname => $upload->{tempname}, filename => $upload->{filename}, ); push @uploads, $u; } $request->uploads->{$name} = @uploads > 1 ? \@uploads : $uploa +ds[0]; # support access to the filename as a normal param my @filenames = map { $_->{filename} } @uploads; # append, if there's already params with this name if (exists $parameters->{$name}) { if (ref $parameters->{$name} eq 'ARRAY') { push @{ $parameters->{$name} }, @filenames; } else { $parameters->{$name} = [ $parameters->{$name}, @filena +mes ]; } } else { $parameters->{$name} = @filenames > 1 ? \@filenames : $fil +enames[0]; } } }
        That's right, I don't.

        Looking at the source, it looks like that happens in Catalyst::Engine::prepare_uploads

        sub prepare_uploads { my ( $self, $c ) = @_; my $request = $c->request; return unless $request->_body; my $uploads = $request->_body->upload; my $parameters = $request->parameters; foreach my $name (keys %$uploads) { my $files = $uploads->{$name}; my @uploads; for my $upload (ref $files eq 'ARRAY' ? @$files : ($files)) { my $headers = HTTP::Headers->new( %{ $upload->{headers} } +); my $u = Catalyst::Request::Upload->new ( size => $upload->{size}, type => $headers->content_type, headers => $headers, tempname => $upload->{tempname}, filename => $upload->{filename}, ); push @uploads, $u; } $request->uploads->{$name} = @uploads > 1 ? \@uploads : $uploa +ds[0]; # support access to the filename as a normal param my @filenames = map { $_->{filename} } @uploads; # append, if there's already params with this name if (exists $parameters->{$name}) { if (ref $parameters->{$name} eq 'ARRAY') { push @{ $parameters->{$name} }, @filenames; } else { $parameters->{$name} = [ $parameters->{$name}, @filena +mes ]; } } else { $parameters->{$name} = @filenames > 1 ? \@filenames : $fil +enames[0]; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://831168]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (18)
As of 2015-07-29 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls