Go to page content

resource_file_readonly

Serve a file or image.

This Webmachine resource is used to serve files and images. It is able to manipulate an image according to the parameters supplied.

Image manipulation parameters are signed to prevent random image manipulations on the request of visitors, which might result in a denial of service due to processing- or disk space limitations.

This resource serves all files with a very long client side caching time. It also handles if-modifies-since checks. And it compresses served files with gzip when the user-agent supports it.

Example dispatch rule:

{image, ["image", '*'], resource_file_readonly, [{is_media_preview, true}]}

Resource_file_readonly has the following dispatch options:

OptionDescriptionExample
rootList of root directories where files are located. Use 'lib' for the library files. This defaults to the site's “files/archive” directory, unless “is_meda_preview” is set then it defaults to the sites’s “files/preview” directory.{root, [lib]}
media_pathThe path for media when “is_media_preview” is set. Defaults to the site’s “files/archive” directory.{media_path, "/var/media/archive"}
path

Default file to be served.  Used for files like “robots.txt” and “favicon.ico”.

(0.6-dev) When set to the atom 'id' then there must be an 'id' argument in the dispatch list.  The file of this resource is then served.

{path,"misc/robots.txt"}

{path, id}

content_dispositionIf the file should be viewed in the browser or downloaded. Possible values are inline and attachment. Defaults to the browser’s defaults by not setting the “Content-Disposition” response header.{content_disposition, inline}
is_media_previewSet to true to allow recognition and handling of image manipulation parameters. See the {% image %} tag for their format. Defaults to false.

{is_media_preview, true}

use_cacheUse server side caching of files. Especially useful when gzip-compressing files. Not so useful when a proxy cache like Varnish is used. Defaults to false.{use_cache, true}

Resource_file_readonly does not handles any query arguments other than the file path.

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.