[Catalyst] C::C::FormBuilder, Request::Upload and file Uploads ?

Stephen Telford stef at ummon.com
Fri Feb 29 19:15:49 GMT 2008


Hey Everyone,
    Okay, potentially stupid question, but, here goes :)

    I  am using Catalyst::Controller::FormBuilder, and I am trying to 
grab the file from inside using the Request::Upload, yet it never gets 
any uploads .. does C::C::FormBuilder and Request::Upload 'play nicely' 
with each other ?

    Here is my Yaml Form;

> name: media_create
> method: post
> enctype: 'multipart/form-data'
> fields:
>   myUploadFile:
>     label: Filename
>     type:  file
>     required: 1
>
> submit: Upload New Media

    And here is the controller in my media create;

> package MyApp::Controller::Media;
>
> use strict;
> use warnings;
> #use base 'Catalyst::Controller';
> use base 'Catalyst::Controller::FormBuilder';
> use Data::Dumper;
> use CGI::FormBuilder;
> sub create : Local Form {
>     my ( $self, $c, @args ) = @_;
>
>     my $form = $self->formbuilder;
>
>     if ( $form->submitted ) {
>       if ( $form->validate ) {
>                 my $upload = $c->request->upload('myUploadFile');
>                 $upload->copy_to('/tmp/blah');
>                 print $upload->md5sum;
>
>                
>                 $c->stash->{notice_msg} = "New Media Created";
>                 return $c->forward('/media/create');
>         }
>     }
>     else {   
>              $c->stash->{error_msg} = "INVALID FORM";
>              $c->stash->{invalid_fields} = [ grep { !$_->validate } 
> $form->fields ];
>     }
>     $c->stash->{template} = 'media/create.tt2';
> }

    Regards
    Stef



More information about the Catalyst mailing list