Up and Download Files to a Device¶
There are two additional endpoints /files/upload/ and files/download/ which allow to upload and download files.
Uploading can be used to send a set of instructions which can then be executed autonomously, for example.
Downloading files is mostly to save the data which was recorded previously.
Both methods can be found in /api/files/routes.py while the default file names can be configured with the right configuration parameters.
Note
Feel free to adjust the up and download methods by your needs but note that, depending on how downloads are triggered
(see Download below), the application may call files/download/ with or without
a file query parameter specifying which file to return.
Upload¶
You can upload file to your device by specifying the file-upload type as an option in your device.json.
If you use the provided implementation, adjust the upload path if needed in config.py. The device will then always override the this file when a new one is uploaded.
However, you can adjust this method as you wish but be careful. Most likely you would then also need to pass the filename for the file to use when executing the instructions stored there. This could be done with an input type for example.
Download¶
There are two ways a download can be triggered:
Pressing the
Download Recordingbutton on the send page of the device (recording must be enabled to see it). This callsfiles/download/without any query parameter, the same rules apply as before: the default filename can be adjusted inconfig.py, and if you adjust this method you must make sure to return the correct file when nofileparameter is present.Selecting a file from a file-download option and pressing download. This calls
files/download/with afilequery parameter set to thevalueof the selected file, and, if the file belongs to a group, an additionallabelquery parameter set to the group name. Your implementation of this method must read these parameters to determine which file (and, if applicable, group/directory) to return.