Created
March 15, 2013 03:57
-
-
Save s4553711/5167381 to your computer and use it in GitHub Desktop.
Render a picture in non-public folder in Mojolicious
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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