[Catalyst] Simple blob upload example?

Dr. Jennifer Nussbaum bg271828 at yahoo.com
Fri Sep 19 19:58:15 BST 2008

--- On Fri, 9/19/08, J. Shirley <jshirley at gmail.com> wrote:

> From: J. Shirley <jshirley at gmail.com>
> Subject: Re: [Catalyst] Simple blob upload example?
> To: bg271828 at yahoo.com, "The elegant MVC web framework" <catalyst at lists.scsys.co.uk>
> Date: Friday, September 19, 2008, 8:52 AM
> On Fri, Sep 19, 2008 at 7:40 AM, Dr. Jennifer Nussbaum
> <bg271828 at yahoo.com> wrote:
> > Hi,
> >
> > Im about to start an app where i'll need to upload
> PDFs from a user and store them in my database. Is there any
> quick example that might show
> > how to do this? I browsed through the wiki and didnt
> see anything. I know its simple but ive never done this
> before.
> >
> > Thanks!
> >
> > Jen
> >
> To divert this a bit, are you -really- sure you want to
> store them in
> a database?  Storing large files in a database is not going
> to be
> ideal, as you'll lose abilities to replicate the files
> in a separate
> policy from you DB, etc.

Yes, but OTOH i gain the ability to back up everything at once, and move onto a different machine or even platform without having to worry about two seperate place.

But this is a holywar that others have fought about for a long time, no need to, ah, replicate it here ;-)

> But to answer your question, the uploads are this object:
> http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7014/lib/Catalyst/Request/Upload.pm
> You can then just do $db_record->contents(
> $upload->slurp );

Yes, i saw the upload object but most of it looked like filesystem stuff, so i wasnt sure what to do then. So if i want to create a new record, for lets say a table called 'image' and a blob field called 'image' with a 'mime_type' description, i just do something like

my $new_record = $c->model('MyDB::Image')->create({ image => $upload->slurp, mime_type => 'application/pdf' });

and thats all i have to do? Wow thats easy!




More information about the Catalyst mailing list