Attached file, property type 'attachment' (using class 'abc/mnesia' and property 'patt' as an example)

Overview

Allows attaching a file attachment to an entity with placement on disk in a preconfigured storage associated with the class collection.
And subsequently performing operations of reading, replacing, and deleting the attachment.

Each property of type `attachment` forms a separate endpoint of this type in the REST API.

After upload the file loses its name and extension and is available for download without these characteristics under the name `content`.

Uploading a file with Content-Type: application/octet-stream and multipart/form-data is allowed. In the latter case, the first file from the list is actually saved. The original file name is taken from the Content-Disposition header and saved in the field metadata (JSON). In storage the file is placed with a special constant name.

The real path to attachments is formed the same way regardless of storage type:
For categories: `…​/Domain/ClassName/Id12/Id34/Id56/IdRest/PropertyName`
For history: `…​/Domain/ClassName/Id12/Id34/Id56/IdRest/PropertyName`

Requests

HTTP verb Endpoint Description

GET

/rest/v1/model/<classname>/<id>/<attachment_property>

Downloading the attachment

PUT

/rest/v1/model/<classname>/<id>/<attachment_property>

Uploading the attachment

DELETE

/rest/v1/model/<classname>/<id>/<attachment_property>

Deleting the attachment


Downloading the attachment

Request

Table 1. Request parameters
Name Type Description

attachment

bool

Output type. Default false.

true – returned with the header Content-Disposition: attachment; filename=filename.ext or Content-Disposition: attachment; filename*=UTF-8''%d1%84%d0%b0%d0%b9%d0%bb.ext, where file.ext is the file name in UTF-8 encoding and URL-encoded.

false – returned without the Content-Disposition header.

Example request
GET /rest/v1/model/abc/mnesia/68f99ca9-016c-d352-e02f-50e54938780c/patt HTTP/1.1

Response

Example response
HTTP/1.1 200 OK
Content-Type: application/octet-stream; charset=utf-8
Content-Disposition: attachment; filename*=UTF-8''Some%20file.mp3

BINARY BODY OF 'Some file.mp3'

Uploading the attachment

Replaces the file.

A single file is uploaded either with Content-Type: multipart/formdata or with an arbitrary non-multipart Content-Type.

If the upload uses Content-Type: multipart/formdata, only the first file is saved (the first part having a filename field in the Content-Disposition header), and the file name itself is ignored.

Request

Example request (octet-stream)
PUT /rest/v1/model/abc/mnesia/68f99ca9-016c-d352-e02f-50e54938780c/patt HTTP/1.1
Content-Type: application/octet-stream

BINARY BODY OF 'app.mp3'
Example request (multipart)
PUT /rest/v1/model/abc/mnesia/68f99ca9-016c-d352-e02f-50e54938780c/patt HTTP/1.1
Content-Type: multipart/form-data; boundary=-----------boundary_69df8120352a996e

-----------boundary_69df8120352a996e
Content-Type: application/octet-stream
Content-Disposition: form-data; name="abcde"; filename="app.mp3"
Content-Transfer-Encoding: binary

BINARY BODY OF 'app.mp3'
-----------boundary_69df8120352a996e--

Response

Example response
HTTP/1.1 204 No Content

Deleting the attachment

Request

Example request
DELETE /rest/v1/model/abc/mnesia/68f99ca9-016c-d352-e02f-50e54938780c/patt HTTP/1.1

Response

Example response
HTTP/1.1 204 No Content