You can do one of two things. I don't know Mojo, but it's no different conceptually than what you'd do with other similar frameworks (e.g., Dancer or CGI::Application).

First, you can put inside of the img tag the URL that Mojo will handle by delivering the static binary image content directly ( don't forget to set content type ). For example, http://path/to/mojo/getImage/<imageID>

Second, you can have your image in a public directory available directly to any web browser. You would then just populate the img's src attribute with this URL using a template or directly generating the content. For example, http://path/too/image.jpg

It seems to me that you're interested in doing the former - having Mojo deliver the binary content of an image (or some file) that is residing in a private directory. This approach requires that Mojo have at least 2 route handers - one to deliver the HTML and one to deliver the image's binary content.

I suppose if you want to get fancy, you could embed the binary content directly in the HTML, but I wouldn't recommend it since it's a very inflexible approach that is typically used only for optimizing certain situations.


In reply to Re^3: Mojolicious: rendering images located outside of public directory by perlfan
in thread Mojolicious: rendering images located outside of public directory by Kyshtynbai

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.