|
|
|
# Storing Files
|
|
|
|
|
|
|
|
The concept to having files saved in the database is that any attribute may be defined as a file.
|
|
|
|
|
|
|
|
```xml
|
|
|
|
<attribute name="attachment" label="one attachment" description="to test the file type" datatype="file" required="false" translatable="false" />
|
|
|
|
```
|
|
|
|
|
|
|
|
In the universe, an attribute can be identified as being a file by it's baseDataType, which is also "file".
|
|
|
|
|
|
|
|
```json
|
|
|
|
"attachment" : {
|
|
|
|
"baseDataType": "file",
|
|
|
|
"dataType": "file",
|
|
|
|
"description": "to test the file type",
|
|
|
|
"displayOrder": 5,
|
|
|
|
"downloadUrl": "/data/helpdesk/ticket/{{id}}/download/attachment",
|
|
|
|
"downloadVerb": "GET",
|
|
|
|
"id": 781,
|
|
|
|
"isReference": false,
|
|
|
|
"isSystemAttribute": false,
|
|
|
|
"label": "one attachment",
|
|
|
|
"name": "attachment",
|
|
|
|
"referenceDetails": null
|
|
|
|
"required": false,
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The attribute's permissions are handled as usual - if it's available in a transition, it may be set.
|
|
|
|
|
|
|
|
To set (upload) a file, it needs to be packed into the json request of any transition which includes it.
|
|
|
|
|
|
|
|
The attribute must be set to the original file name and the base64 encoded file data, seperated by a semi-colon:
|
|
|
|
|
|
|
|
```
|
|
|
|
#/data/helpdesk/ticket/transitions/create
|
|
|
|
{
|
|
|
|
"category" : 1,
|
|
|
|
"subject" : "test",
|
|
|
|
"attachment" : "test.txt;Ymxh"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
As seen in the reply, the attribute will be replaced with meta data needed to store and retrieve the file.
|
|
|
|
|
|
|
|
```
|
|
|
|
"data": {
|
|
|
|
"modification_time": "2019-06-05T12:00:58.580746",
|
|
|
|
"cost_bearing_department": null,
|
|
|
|
"id": 3,
|
|
|
|
"subject": "test",
|
|
|
|
"owning_client": 1,
|
|
|
|
"instance_entity": 81,
|
|
|
|
"category": 1,
|
|
|
|
"attachment": {
|
|
|
|
"original_name": "test.txt",
|
|
|
|
"path": "/ironapi-gw/script/../var/upload/d11c97da-8778-11e9-ad30-0242ac180003",
|
|
|
|
"mime_type": "text/plain"
|
|
|
|
},
|
|
|
|
"modifying_client": 1,
|
|
|
|
"successor": null,
|
|
|
|
"modifying_action": 288
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
As stated in the universe, the file itself can be downloaded via a seperate url:
|
|
|
|
**
|
|
|
|
/data/helpdesk/ticket/3/download/attachment**
|
|
|
|
|
|
|
|
Permission to do so will be the same as a permission to view the instance. |
|
|
|
\ No newline at end of file |