Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created March 15, 2013 03:57
Show Gist options
  • Save s4553711/5167381 to your computer and use it in GitHub Desktop.
Save s4553711/5167381 to your computer and use it in GitHub Desktop.
Render a picture in non-public folder in Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->render('clock');
};
get '/pic' => sub {
my $self = shift;
my $src = '/opt/private-folder/good.png';
$self->res->headers->content_type('image/png');
$self->res->content->asset(Mojo::Asset::File->new(path => $src ));
$self->rendered();
};
app->start;
__DATA__
@@ clock.html.ep
% use Time::Piece;
% my $now = localtime;
The time is <%= $now->hms %>.
<img src="http://127.0.0.1:3000/pic"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment