1. Attachments

Attachments

How files work in Stubber: what a file object is, where a stub's files are kept, and how to attach files with tasks, form fields and notifications.

File objects

Uploaded files are stored on Stubber's file server. Your process never holds a file's content, only a small file object that points to it:

loading...
Key Description
fileuuid The file's unique ID on the file server. This is the only required key.
filename The name shown on the stub.
originalname The file's name when it was uploaded.
contentType The file's MIME type, eg. application/pdf.

Some file objects have extra keys, such as f_id on files uploaded through a form. You can ignore them.

A file object is plain JSON, so you can pass it between tasks, notifications and stubs without copying the file. See Files And File Handling for how Stubber stores files.

Where a stub's files are kept

stub.attachments

Every stub has an attachments array holding a file object for each file attached to it. The Files tab on a stub shows this array.

loading...

stubpost.attachments

Each stubpost also has an attachments array, but it only holds the files attached during that action.

Substituting files

Use substitution wherever a file object or list of file objects is expected:

  • ~~stub.attachments - every file on the stub
  • ~~stub.attachments[0] - the first file object on the stub
  • ~~stub.attachments[0].fileuuid - the UUID of the first file
  • ~~stubpost.attachments - the files attached in the current action

Attaching files with tasks

Task Use it to
upload_file Fetch a file from a URL or data URI and attach it to the stub.
attach_file Attach a file that is already on Stubber's file server.
remove_attachment Remove a file from the stub.

upload_file

Use upload_file when the file is not on Stubber yet.

loading...

attach_file

Use attach_file when the file is already on Stubber, for example a file made by an earlier task. Pass a fileuuid or a full file object.

loading...

To copy every file from one stub to another, use "files": "~~stub.attachments".

INFO

Some tasks attach the files they create automatically, such as Generate PDF and Extract Zip File. Check each task's documentation.

Attaching files with a file field

Add a file field to an action form to let users upload files when they run the action:

loading...

When the action is submitted:

  1. The uploaded files are attached to the stub, so they appear in stub.attachments and on the Files tab.
  2. The field's value is saved as an array of file objects under the field's name, in both stubpost.data and stub.data.

For the field above, the stubpost contains:

loading...

The value is an array, so use an index to get a single file:

  • ~~stubpost.data.supporting_documents - every file uploaded in this field
  • ~~stubpost.data.supporting_documents[0] - the first file object
  • ~~stubpost.data.supporting_documents[0].fileuuid - the UUID of the first file

In later actions, read the files from stub.data.supporting_documents instead.

TIP

stub.attachments holds every file on the stub. A field's value only holds the files uploaded in that field, so use it when you need a specific document, like "the ID document the customer uploaded".

Sending files in notifications

Notifications accept file objects or file UUIDs, just like tasks: