Ave

I'm trying to render an image (with its name) via a Mojolicious::Lite app. Note that a full path to the file is given and putting a link in "public" isn't very appealing. No doubt someone will say don't do that it's a security problem - but the app is only for my own use.

The app:

#!/usr/local/bin/perl use warnings; use Data::Dumper; use Mojolicious::Lite -signatures; use Mojolicious::Static; # Let's just say all we know about the image is my $directory = 'c:/xyzzy/test/'; # some arbitrary directory my $name = 'TEST'; my $extension = '.jpg'; # And we want to create the page as in "picture.html.ep" get '/picture' => sub($c) { #my $static = Mojolicious::Static->new; $c->stash(name=>$name,extension=>$extension); # The following generates #" Can't locate object method "static" via package "Mojolicious::C +ontroller"" warn Data::Dumper->new([\$c->static->paths],[qw(path)])->Dump(),q{ + }; push @{$c->static->paths}, $directory; warn Data::Dumper->new([\$c->static->paths],[qw(path)])->Dump(),q{ + }; }; app->start; __DATA__ @@ picture.html.ep <!DOCTYPE HTML> <html> <body> <h2><%== $directory.$name.$extension %></h2> <img src="<%== $name.$extension %>" alt="FAILED!" /> </body> </html>

So how does one supplement/modify/alter the path that Mojolicious::Lite uses to serve public files?


In reply to Rendering a file in any directory via Mojolicious::Lite by clueless newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.