[Catalyst] Simple blob upload example?

Dr. Jennifer Nussbaum bg271828 at yahoo.com
Tue Sep 23 20:30:27 BST 2008



--- On Fri, 9/19/08, Dr. Jennifer Nussbaum <bg271828 at yahoo.com> wrote:

> From: Dr. Jennifer Nussbaum <bg271828 at yahoo.com>
> Subject: Re: [Catalyst] Simple blob upload example?
> To: "The elegant MVC web framework" <catalyst at lists.scsys.co.uk>, "J. Shirley" <jshirley at gmail.com>
> Date: Friday, September 19, 2008, 11:58 AM
> --- 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!

I did just want to report that i did this and it worked perfectly. My actual line was:

$c->model('MyDB::Image')->create({ image => $upload->slurp, type => $upload->type });

I figured that i should use $upload->type so that just in case i later want to upload gifs or something i wouldnt have to change code.

Perfect, simple, it worked. 

Thanks!

Jen

Thanks!


      



More information about the Catalyst mailing list