unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Martyn Smith <martyn.developer@googlemail.com>
To: Nala Ginrut <nalaginrut@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: Learning Guile web. Stuck on returning an image.
Date: Fri, 11 Dec 2015 11:46:13 +0000	[thread overview]
Message-ID: <CA+dhi3sxPkkPMWYaxsEqrwUaet+rm7sSyr6S+3ZYQNLo0jZ1fw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2656 bytes --]

Thanks for extra suggestions!

I am using the (init-server #:static ...) for my website as it includes
css, js, images, etc.

For my family photos, I wanted them to be kept hidden from the public,
which is why I mentioned the "/image/{id}" at the end. You have to be
logged in to the site in order to view them, as well as various other
features it supports.

With that in mind -- I will be trying emit-response-with-file when I next
have the source code in front of me. This is a better approach rather than
handling mime, etc. I am surprised I did not come across this function
myself in the documentation. Although it has been a while since i last
properly reviewed the docs. Probably did not think it would have been
useful at the time? Regardless, I should check to see what extra cool
features are included in Artanis now!

Thanks again,
M



On Fri, Dec 11, 2015 at 6:31 AM, Nala Ginrut <nalaginrut@gmail.com> wrote:

> Hi Martyn!
> I'm very glad to see a new user of Artanis!
>
> On Thu, 2015-12-10 at 19:44 +0000, Martyn Smith wrote:
> > (use-modules (artanis artanis)
> >                      (rnrs io ports))
> >
> > (init-server)
> >
> > (get "/image"
> >      (lambda (rc)
> >        (let* ((port (open-file "s.jpg" "r"))
> >                (bytes (get-bytevector-all port)))
> >      (close-port port)
> >      (response-emit bytes #:headers '((content-type image/jpg))))))
> >
> > (run #:port 1234)
> >
>
> In this case, you have three more alternatives to try. It is not
> recommended to handle static files manually. Such work is treated as
> low-level in Artanis.
>
> 1. Static files handling
> This would be done by (init-server #:statics '(jpg)) or add more static
> files ext-filename as you wish.
> In this way, you don't have to write rules & handlers, say, you don't
> need (get ...). Artanis will handle jpg files and detect correct MIME
> for you, and proper cache expires according to your config file.
>
> 2. Use emit-response-with-file
> http://www.gnu.org/software/artanis/manual/manual.html#sec-6-4
>
> Sometimes, you don't want to reveal the jpg filename, say,
> (get "/image"
>   (lambda (rc) (emit-response-with-file "s.jpg")))
>
> Of course, you don't have to specify MIME, but no cache option (ETag)
> specified too. Unless you specify it explicitly. This method is used for
> MVC to emit HTML template of Views automatically. Because sometimes we
> don't want Artanis to add caching for us cleverly.
>
> 3. Take advantage of #:cache shortcut
> For static files, we often want to emit it with caching.
> (get "/image" #:cache '(public "s.jpg" #:maxage 3600)
>   (lambda (rc)
>     (:cache rc)))
>
>
> Happy hacking!
>
>

[-- Attachment #2: Type: text/html, Size: 3648 bytes --]

             reply	other threads:[~2015-12-11 11:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-11 11:46 Martyn Smith [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-05-25 22:30 Learning Guile web. Stuck on returning an image Martyn Smith
2014-05-26  0:22 ` Nala Ginrut
2014-05-26  9:05 ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+dhi3sxPkkPMWYaxsEqrwUaet+rm7sSyr6S+3ZYQNLo0jZ1fw@mail.gmail.com \
    --to=martyn.developer@googlemail.com \
    --cc=guile-user@gnu.org \
    --cc=nalaginrut@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).