File Download¶
This option allows the user to select and download a file from the device, for example previously recorded data or a stored curve.
Tag¶
"type": "file-download"
Values¶
The file-download type supports the following values:
files¶
An array of files which the user can choose from to download. This can be configured in three ways:
A flat array of file names:
"files": ["sample.csv", "curve.json"]
An array of objects with a separate display text and value:
"files": [
{"text": "Sample data", "value": "sample.csv"},
{"text": "Curve data", "value": "curve.json"}
]
Or grouped into categories, for example to group files by folder:
"files": [
{
"label": "curves",
"options": [
{"text": "sample.csv", "value": "curves/sample.csv"}
]
}
]
When a file from a group is selected, the group’s label is also sent to the device, so the device can locate the file even if multiple groups contain files with the same value (see Argument Passed to the Device).
If omitted, no files are offered for download.
Note
Unlike file-upload, setting the optional tag refresh
(see Optional Option Tags) on this option has no effect - the device
information and dashboard are not reloaded after a download.
Argument Passed to the Device¶
This option does not pass any parameter to device.execute. Instead, when the user selects a file and presses the download button, the app requests it from /files/download/ with the chosen value attached as the file query parameter, e.g. /files/download/?file=curve.json.
If the selected file came from a grouped files entry, the group’s label is additionally sent as a label query parameter, e.g. /files/download/?file=curves/sample.csv&label=curves. For a flat (ungrouped) files list, no label parameter is sent at all.
Note
This is a special type. It does not pass any value to device.execute. Thus you must not add a parameter there.
Note
Your implementation of /files/download/ must read the file query parameter to determine which file to return, and,
if you group your files, the label query parameter to determine which group/directory to look in.
See Download for more details.
Example¶
This example shows how this type of option will look in the webapp.
Option configuration¶
{
"name": "Download recorded curve",
"type": "file-download",
"id": "download-1",
"values": {
"files": [
{"text": "Sample data", "value": "sample.csv"},
{"text": "Curve data", "value": "curve.json"},
{
"label": "curves",
"options": [
{"text": "Test curve", "value": "curves/test.csv"}
]
}
]
}
}
When the user selects “Curve data” (a flat entry) and presses the download button, the following request is made:
GET /files/download/?file=curve.json
When the user instead selects “Test curve” (part of the curves group), the group’s label is also sent:
GET /files/download/?file=curves/test.csv&label=curves