Super Simple Photo Gallery

Let's create an extremely simple (but fun!) photogallery.
First things first, we need to make sure we have everything.

Our packing list:

DBIx::Class::InflateColumn::FS

This will be used to store our file pointer in the database, write the
image to the file system, and later, give us a Path::Class::File
object to manipulate our images later on.

Imager

The all and the everything for our image manipulation needs. If not
installed already, make sure you install libjpeg so that JPEG files
can be manipulated by Imager.

MIME::Types

File::Mimeinfo

DateTime

Catalyst::Controller::HTML::FormFu

Once you have installed these modules, move on to the next step.

Let's get started already!

Ok. So here comes the fun stuff. We're going to assume you know how
to create a Catalyst application skeleton, controllers, and models at
the very least. If not, you have some documentation to read first :-)

Create a controller in your application called Photos as follows:

perl script/myapp_create.pl controller Photos

Next, you'll want to set up a table called Photos in your RDBMS of
choice. Here, I've used MySQL, but you could use SQLite , Postresql
or any other RDBMS supported by DBIx::Class. The necessary columns
you will need are as follows:

photoid

type: INT
size: 11
null: no
other: PRIMARY KEY auto_increment

name

type: VARCHAR
size: 255
null: no
other:

mime

type: VARCHAR
size: 255
null: no
other:

mime

type: VARCHAR
size: 255
null: no
other:

uploaded

type: DATETIME
size:
null: no
other:
(If you want, include the InflateColumn::DateTime component to be
able to manipulate this column as if it were a DateTime object)

So now you have your basic tables set up. Next, we need to generate
our Schema files so DBIx::Class can interact with our database
objects. I use this script to update/create my schema definition from
the database. Copy/paste this script into a file called
myapp_update_schema.pl (replace "myapp" with whatever you named this
application) and stick it in the script/ directory of your
application: