Nested file, property type 'list of attachments' (using the example of class 'abc/mnesia' and property 'patts')

Overview

Allows an arbitrary number of attachment files to be attached to an entity, with placement on disk in a preconfigured storage associated with the class collection.
And further perform operations of reading, replacing, deleting the attachment.

Each property of type `list of attachments` forms a separate endpoint of that type in REST-API. This is a field of type `attachment` with the set attribute `multi`=`true`.

A file after POST upload retains its name and extension, and when uploaded by PUT method acquires a name and extension identical to the specified attachment identifier.

It is allowed to upload several files with one POST-request in the mode `multipart/form-data`.

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

Requests

HTTP verb Endpoint Description

GET

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

Obtaining metadata for all attachment files associated with the property

GET

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

Downloading a specific attachment file

PUT

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

Uploading an attachment file

DELETE

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

Deleting an attachment file


Uploading attachment files with saving names

Uploading to the collection is done by Content-Type: multipart/formdata.

There can be one or more files in the request. The files are placed under the names specified in the Content-Disposition headers of each part.

If a file with the specified name already exists, it is not saved and returns an error. Depending on the Content-Type and the presence of successfully placed files, the request may return a failed HTTP response, or failure information in the body of the HTTP response 200 OK.

Request

Request example
POST /rest/v1/model/abc/mnesia/6f7d27df-017b-ab81-77e7-7cd30a921f58/patts HTTP/1.1
Content-Type: multipart/form-data; boundary=-----------boundary_69df8120352a996e

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

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

Response

Response example
[
  {
    "name": "F.zip",
    "size": 8411,
    "last_modified": "2019-09-20 10:45:41"
  },
  {
    "name": "Package.bin",
    "size": 12268,
    "last_modified": "2019-09-20 10:45:49"
  }
]

Obtaining metadata for all attachment files associated with the property

Request

Request example
GET /rest/v1/model/abc/mnesia/6f7d27df-017b-ab81-77e7-7cd30a921f58/patts HTTP/1.1

Response

Response example
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

[
  {
    "name": "F.zip",
    "size": 8411,
    "last_modified": "2019-09-20 10:45:41"
  },
  {
    "name": "Package.bin",
    "size": 12268,
    "last_modified": "2019-09-20 10:45:49"
  }
]

Downloading a specific attachment file

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/6f7d27df-017b-ab81-77e7-7cd30a921f58/patts/app.mp3 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'

Uploading an attachment file

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/6f7d27df-017b-ab81-77e7-7cd30a921f58/patts/app.mp3 HTTP/1.1
Content-Type: application/octet-stream

BINARY BODY OF 'app.mp3'
Request example (multipart)
PUT /rest/v1/model/abc/mnesia/6f7d27df-017b-ab81-77e7-7cd30a921f58/patts/app.mp3 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 file

Request

Request example
DELETE /rest/v1/model/abc/mnesia/6f7d27df-017b-ab81-77e7-7cd30a921f58/patts/app.mp3 HTTP/1.1

Response

Response example
HTTP/1.1 204 No Content