clueless newbie has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Rendering a file in any directory via Mojolicious::Lite
by marto (Cardinal) on Feb 07, 2024 at 09:40 UTC | |
by clueless newbie (Curate) on Feb 07, 2024 at 15:08 UTC | |
by marto (Cardinal) on Feb 07, 2024 at 16:34 UTC |