Docs »

Automations »

interaction.worker »

Elements »

File Upload

In interaction web forms, a fileUpload element displays a file upload prompt. This creates an attachment record and returns its record ID.

The element name (e.g. fileUpload/photo in the example below) is used to set a placeholder. If the name ends with _id then a corresponding __context key will be added with the same prefix. Otherwise, keys for _id and __context will be added with the element name as the prefix.

This allows key expansion of the file’s fields (e.g. name, size) directly on the placeholder, as well as from within a validation@raw: script.



start:
  await:
    form:
      elements:
        fileUpload/photo:
          label: Upload a photo:


Syntax

label:

The optional label to display above the form element.

required@bool:

If user input is required on this element use a value of yes. Otherwise, omit.

validation:

An optional custom validation script. Any output is considered to be an error.

You can use if...elseif to check multiple conditions.



start:
  await:
    form:
      elements:
        fileUpload/prompt_image:
          label: File
          required@bool: yes
          validation@raw:
            {% if prompt_image__context is empty or prompt_image_id is empty %}
            The file must be a valid image.
            {% elseif prompt_image_mime_type is not prefixed ('image/') %}
            The file must be an image ({{prompt_image_mime_type}}).
            {% elseif prompt_image_size > 50000 %}
            The image must be smaller than 50KB ({{prompt_image_size|bytes_pretty}}).
            {% endif %}