[Catalyst] Directory with Catalyst::Model::File

Xavier Robin robin0 at etu.unige.ch
Wed Dec 20 10:59:36 GMT 2006


Hello,

I want to save uploaded files in a directory specific for the user (using the 
user_id). For example, the files of user 326 would be saved in 
directory /root/files/3/2/6/.

I use Catalyst::Model::File to do this. It's really great!
I configured it to store files in /root/files/ by default (root_dir). Now I 
use the following code for a specific file:

> my @path = split('', $c->user->user_id);
> my $file_obj = $c->model('File')->file(@path , $filename);

But the file "test.txt" for user "326" is saved as /root/files/3 instead 
of /root/files/3/2/6/test.txt.

It looks like C::M::File uses only the first argument and ignores all the 
others, unlike Path::Class::File that allows to define the path with a list 
of arguments.

I could fix the problem by using the following code where I pass a single 
argument with the complete path: 

> my @path = split('', $c->user->user_id);
> my $path = join ('/', @path);
> my $file_obj = $c->model('File')->file($path . '/' . $filename);

But I find the Path::Class::File syntax looks much smarter and more 
platform-independant. Is there an different syntax for C::M::File?

Thanks for this great framework !

Xavier



More information about the Catalyst mailing list