The "files" action

The "files" action generates files (see Generating files), and makes them available at a temporary URL. This is most useful in concert with the mechanic/actions/perform topic (see Responding to action results) – this pairing allows you to generate a file, and then do whatever you like with the resulting URL. Commonly, this means sending it to an external service using the "http" action. Best use of this we've seen so far: rendering PDFs, then printing them automatically with Printnode. :)


This action accepts a hash, where the keys are filenames and the values are whatever options are appropriate for the file generator you're using. This action is called "files", instead of "file", because many files can be defined in a single action.

To learn more about defining file content, see Generating files.


This action returns a hash having the same keys as its input – one for each supplied filename. Each associated value has these attributes:

  • "expires_at" – an ISO8601 time, specifying when the file will no longer be available
  • "mime_type" – the MIME type of the file, based on its file extension
  • "name" – the filename supplied
  • "size" – the size of the generated file, in bytes
  • "url" – the Mechanic-hosted URL where this file is temporarily available


This task generates a simple PDF, and echo's back its download URL.




{% if event.topic == "mechanic/user/trigger" %}
  {% action "files" %}
      "greeting.pdf": {
        "pdf": {
          "html": "<h1>Welcome!</h1>"
  {% endaction %}
{% elsif event.topic == "mechanic/actions/perform" %}
  {% assign file =["greeting.pdf"] %}
  {% log file_url: file.url %}
{% endif %}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.