[Catalyst] Serve blob files into src="" type tags

Bill Moseley moseley at hank.org
Sat Mar 11 19:29:22 CET 2006


On Sat, Mar 11, 2006 at 10:07:24AM -0800, apv wrote:
>    Has anyone coded up a Static::Simple for DB data?

I have a controller I use for serving thumbnail images related to
a user's account.

The only thing special I do is (I use CDBI and Postgresql):

  __PACKAGE__->data_type( image => { pg_type => DBD::Pg::PG_BYTEA } );

Then my controller something like:

sub photos : Local {
    my ( $self, $c, $id ) = @_;

    my $image = DB::PersonPhoto->get_image( $id );

    unless ( $image ) {
        $c->res->status( 404 );
        return;
    }

    my $res = $c->res;

    $res->body( $image->{image} );
    $res->content_type( $image->{mime} || 'image/jpeg' );

    $res->headers->last_modified( $image->{last_modified} );
    $res->headers->header( 'Cache-Control' => 'max-age=86400' );
    $res->headers->expires( time + 86400 );
}




-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list