Force download of asset file from template I have a template called download that receives an asset ID, looks it up and should force the browser to download the file. I've gotten this far with the {% headers %} tag, but I can't figure out how to read the raw contents of the file and output it.

{% set asset = craft.assets.id(craft.request.getLastSegment()).first() %}
{% header 'Content-Description: File Transfer' %}
{% header 'Content-Type: '~asset.mimetype %}
{% header 'Content-Disposition: attachment; filename='~asset.filename %}
{% header 'Content-Transfer-Encoding: binary' %}
{% header 'Expires: 0' %}
{% header 'Cache-Control: must-revalidate' %}
{% header 'Pragma: public' %}
{% header 'Content-Length: '~asset.size %}
{# How to print raw contents of asset.url ??? #}


Can anyone help?
I don't think you're going to be able to do this out-of-the-box, but should be stupidly simple with a quick plugin that registers its own Twig extension.  See here for an example.

That extension would add a Twig function that's basically just a simple wrapper for PHP's file_get_contents.

Then from your template, you'd do something like:

{# Get the file contents #}
{% set contents = file('/path/to/asset.zip') %}

{# output it #}
{{ contents }}