A file, and any media file can be loaded into Snap4City via the File Manager. Each file is managed as an Entity which is an instance of an Entity Model, which in turn can be customized.
The File Manager is a manager of the HLT and it is accessible for mid nad high level administrator of the platform, while the access to the files depends on the delegation provided by the file owners as usual for all the entities and devices on Snap4City platform and technology.
The upload of a file can be performed via PHP form or API
To upload a new file (“+Add new File”) a form opens requesting the following metadata, you can also call it from API:
- Description(input field)
- Language(list of your choice with available languages)
- Subnature(list of your choice)
- Filetype (choice list retrieved from db)
- Coordinates set via a map
By selecting the document of interest, a preventive check is carried out on the correspondence between the chosen and actual file extension.
Confirming the form makes a call to the getfiledata.php file with action==upload_file.
The metadata is therefore recovered from the form in POST mode and the file is saved, after a further check on the file extension.
A unique dummy id is created, based on timestamp, and the file is saved with the new id in the subdirectory (write and execute permissions -wx) with the same id created in protecteduploads; the file's permissions are revoked. The file is therefore not accessible with http protocol. After retrieving the fileModel model via API, an iot_device related to the file is created, via API (api/device.php) with 'insert' action, as an instance of that model. The device attributes are described later in the model insertion section. An additional API call with 'Insert_value' action is required to actually assign attribute values to the device. The iot_device id is created as a hash of the name + timestamp.
When the page loads, the information of all the files to which the user has access is retrieved, with a call to getfiledata.php and action==get_my_files. This happens via further API calls: the first, with 'get_all_device' action and filtering on the device type (devicetype=='file'), retrieves the files of which the user owns the ownership, public, or for which he has received a delegation; the second, with the 'get_device_data' action, retrieves the values of the selected device attributes. A RootAdmin user has access to all uploaded files.
The view button allows you to download the file through a recovery process from the protected location where it was saved. Only the user who uploaded it (visibility== myownprivate or myownpublic), who has received a delegation or if the file is public (visibility== public or delegated) or a RootAdmin user.
Through the file edit operation it is possible to modify some metadata, in particular subnature, description and the GPS coordinates of the file. The operation updates the attributes of the iot_device via API (dateObserved is updated with the metadata modification date).
The delete operation deletes the iot_device by id and deletes the file and its subdirectory.
Finally, the ownership button allows you to manage the ownership, visibility and delegations of the file. It is possible to change the ownership of the file by entering the username of the new owner, change the visibility from public to private and vice versa (by default the devices are created with private visibility) and finally delegate a username or a group to have access to the file. These features are active only in case of ownership of the device and therefore visibility=myownprivate or myownpublic. Otherwise the ownership will have a value between: private, public and delegated.
However, only the user who owns the file (visibility== myownprivate or myownpublic) or a RootAdmin user has access to the edit and delete functions.
Please refer to the following diagram for the creation of the model and attributes.
Name (model name) |
fileModel |
Description |
fileModel |
Device Type |
file |
Kind |
sensor |
Producer |
|
Frequency |
600 |
ContextBroker |
DISIT (in the iotobsf vm) |
Attributes table
Value Name |
Value Type |
Data Type |
Value Unit |
Notes |
dateObserved |
timestamp |
string |
milliseconds |
Date the file was uploaded or last modified |
originalfilename |
entity_desc |
string |
text |
Original name of the uploaded file |
newfileid |
entity_desc |
string |
text |
Fictitious ID with which the file was saved |
language |
entity_desc |
string |
text |
|
description |
entity_desc |
string |
text |
User description |
filesize |
entity_desc |
string |
text |
Calculated upon loading in Kbytes |
filetype |
entity_desc |
string |
text |
File extension |