Nested file, property type 'attachment' (using the example of class 'abc/mnesia' and property 'patt')

Overview

Allows an attachment file to be attached to an entity with a disk location in the preconfigured storage associated with the class collection.
And further perform operations of reading, replacing, deleting the attachment.

Each property of type `attachment` forms a separate endpoint of that type in REST-API.

The file loses its name and extension after download, and is available for download with these characteristics lost under the name of `content`.

It is allowed to upload a file with content-type application/octet-stream and multipart/form-data. In the latter case, the first of the file list is actually saved.

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

Requests

HTTP verb Endpoint Description

GET

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

Downloading an attachment

PUT

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

Pouring an attachment

DELETE

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

Deleting an attachment


Downloading an attachment

Request

Table 1. Request parameters
Name Type Description

attachment

bool

Issuance Type. Default false.

true – is output 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 URLencoded.

false – untitled Content-Disposition.

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

Response

Response example
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'

Pouring an attachment

Performs a file replacement.

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

If the download is done with Content-Type: multipart/formdata, then only the first file will be saved (the first part with the filename field in the header) Content-Disposition), and the file name itself will be ignored.

Request

Request example (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'
Request example (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

Response example
HTTP/1.1 204 No Content

Deleting an attachment

Request

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

Response

Response example
HTTP/1.1 204 No Content