Uploading files
Uploading one or more files is implemented in a plugin, aptly called ‘uploads’. This is included in the web version of xxllnc Expertsystemen, so you can immediately try it out from your modeling environment.
You can add an upload widget to any node that already contains text and/or questions.
To add an upload widget, at at least the following metadata to the node:
setmetadata('uploads.0.id', '<some unique id>');
setmetadata('uploads.0.text', 'Header text');
- id: needed for plugin to lump uploaded files together. It also
- text: header text for file upload.
You can have multiple upload widgets per node. That’s what the 0
index is for.
A second widget would be declared with index 1
:
setmetadata('uploads.1.id', '<some OTHER id>');
setmetadata('uploads.1.text', 'Second header text');
NOTE there are no gaps allowed in between the indices: so index 0
must be followed by 1
. Following 0
with 2
for instance is not supported.
Optional properties:
The optional properties described below are all declared with
setmetadata('uploads.<index>.<property>', <value>);
For brevity’s sake, we just list the property name here:
-
mimetypes
: a comma-separated list of extensions (not mimetypes currently - the server only looks at extensions).E.g.
'.jpeg,.jpg,.pdf'
to allow for any JPG file and regular PDFs.PDFs with forms and encrypted PDFs are by default not allowed when you include the
.pdf
extension. You can opt-in to them with the pseudo-extensions.pdff
(forms) and.pdfe
(encrypted).You can also opt-out of regular PDF files by only including
.pdff
and/or.pdfe
. -
maxmb
: maximum upload size in MBNOTE Setting this higher than the server-wide setting will lead to the file being rejected. The server only checks the server-wide setting.
-
preview
: 0 or 1: show an inline preview for the uploaded file -
multiple
: 0 or 1: allow upload of multiple files -
onebyone
: 0 or 1: (when multiple is 1): only allow one at a time -
err_duplicate_name
: custom error message for when file has been uploaded earlier -
err_duplicate_name_same_upload_id
: custom error message for when file has been earlier for same upload id -
allow_duplicate_names
: 0 or 1: do not err on duplicate name (server will append a (1), (2), etc. before the file extension) -
in_table
: 0 or 1: put the tag and file upload fields inside the results table, on the very last row -
text_help
: extra (paragraph) text, rendered w/ markdown and below header -
text_select
: label text for file input -
text_add
: text for button to add a new row (only used whenin_table
is true) -
position
: when present, specifies the postion where the widget ought to be placed.As strings are allowed the following, ‘beforeBegin’, ‘afterBegin’, ‘beforeEnd’ and ‘afterEnd’ (the default). These place the widget relative to the group (the node) itself.
If numerical, the widget is placed after the nth (zero-based) form-group.
If the provided value does not lead to a valid position (e.g. with wrong string or a form-group number that does not exists in the current node), the widget will be placed after the current node.
NOTE that nested form-groups are also counted and
NOTE that for relative-to-question positioning core grouping should be turned on in the presentation layer (
arbitrary.core.form-group.on=true
in the conf.json). See also Look and feel > CSS > Question/text structure.
Tags
Tags can be used to store extra information with the uploaded file;
the value of a tag can either be provided by the end-user or be a
constant. The values can be inspected in the model using
sessionfiletag(<filename>, <tagname>)
;
Required properties for tags:
-
name
: name for the tag -
text
: label for the tag (not needed when type = “constant”) -
type
:'constant'
,'dropdown'
or'date'
. A constant will be saved as-is (no user interaction).When the type is
'constant'
, add a'value'
property.When the type is
'dropdown'
, add a list of indexed options:setmetadata('uploads.<index>.tags.<index>.options.0', 'passport'); setmetadata('uploads.<index>.tags.<index>.options.1', 'driver''s license'); setmetadata('uploads.<index>.tags.<index>.options.2', 'library card');
When the type id
'date'
, you MAY add aminimum
ormaximum
property, with the format of yyyy-mm-dd.
Optional properties for tags:
list
: list the value of the tag in the overview / deletion table (0
or1
).required
: the tag is required (cannot upload if empty).
Tags are also indexed, as uploads.<index>.tags.<tagindex>.type
, etcetera.
Examples
Now, this all being overtly technical, below are a few examples, hopefully saying more than all these words.
Upload multiple files, adding tags such as category and date of issue, after the first element (title or text probably)
setmetadata('uploads.0.id', 'tv/diplomas');
setmetadata('uploads.0.text', 'upload your diplomas...');
setmetadata('uploads.0.mimetypes', '.pdf,.jpg,.xlsx,.xls,.docx,.doc');
setmetadata('uploads.0.multiple', 1);
setmetadata('uploads.0.onebyone', 1);
setmetadata('uploads.0.maxmb', 5);
setmetadata('uploads.0.preview', 0);
setmetadata('uploads.0.err_duplicate_name', 'No! File exists');
setmetadata('uploads.0.err_duplicate_name_same_upload_id', 'No! File is already in the list');
setmetadata('uploads.0.allow_duplicate_names', 1);
setmetadata('uploads.0.position', 0);
setmetadata('uploads.0.tags.0.type', 'date');
setmetadata('uploads.0.tags.0.name', 'issuedate');
setmetadata('uploads.0.tags.0.text', 'issue date');
setmetadata('uploads.0.tags.0.minimum', timestamp('yyyy-mm-dd'));
setmetadata('uploads.0.tags.1.type', 'dropdown');
setmetadata('uploads.0.tags.1.name', 'category');
setmetadata('uploads.0.tags.1.text', 'Category');
setmetadata('uploads.0.tags.1.options.0', 'diploma');
setmetadata('uploads.0.tags.1.options.1', 'work experience');
setmetadata('uploads.0.tags.2.type', 'constant');
setmetadata('uploads.0.tags.2.name', 'type');
setmetadata('uploads.0.tags.2.value', 'documents');
setmetadata('uploads.0.tags.2.type', 'constant');
setmetadata('uploads.0.tags.2.name', 'node');
setmetadata('uploads.0.tags.2.value', 'main.files');
Which would lead to a tag file such as the following:
id=tv/diplomas
issuedate=2019-02-23
category=diploma
type=documents
node=main.files
Upload single photo, with a preview, at the start of the node
setmetadata('uploads.1.id', 'tv/passportphoto');
setmetadata('uploads.1.text', 'upload your passport photo');
setmetadata('uploads.1.mimetypes', '.jpeg,.jpg,.png');
setmetadata('uploads.1.multiple', 0);
setmetadata('uploads.1.maxmb', 5);
setmetadata('uploads.1.preview', 1);
setmetadata('uploads.1.position', 'afterBegin');
setmetadata('uploads.1.tags.0.type', 'constant');
setmetadata('uploads.1.tags.0.name', 'type');
setmetadata('uploads.1.tags.0.value', 'passportphoto');
Giving us the following tag file on upload:
id=tv/passportphoto
type=passportphoto