--- On Fri, 9/19/08, J. Shirley <[EMAIL PROTECTED]> wrote:

> From: J. Shirley <[EMAIL PROTECTED]>
> Subject: Re: [Catalyst] Simple blob upload example?
> To: [EMAIL PROTECTED], "The elegant MVC web framework" 
> <catalyst@lists.scsys.co.uk>
> Date: Friday, September 19, 2008, 8:52 AM
> On Fri, Sep 19, 2008 at 7:40 AM, Dr. Jennifer Nussbaum
> <[EMAIL PROTECTED]> 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!

Thanks,

Jen


      

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to