Skip to main content

Attachments

How to Work with Attachments

Written by Lenka Haringerová

For records that support attachments, attachments can be listed, created, and deleted via the REST API. This article describes each operation, including working with images and with the company logo in settings.


Exporting an attachment

For records that support attachments, you can display a list of attachments as follows:

/c/firma/adresar/12/prilohy

Metadata for a specific attachment can be retrieved in the usual way:

/c/firma/adresar/12/prilohy/75

The binary data of an attachment can be retrieved using GET; the response also includes the correct Content-Type header:

/c/firma/adresar/12/prilohy/75/content

If the attachment is an image, you can retrieve a thumbnail in a similar way (if none exists, the response will be a 404 error):

/c/firma/adresar/12/prilohy/75/thumbnail


Importing a binary file

An attachment can also be created via PUT; you must specify the file name and send its type in the Content-Type header:

PUT /c/firma/adresar/12/prilohy/new/název souboru 
Content-Type: image/jpeg

The attachment's binary data must be included in the request body.

⚠️ An existing attachment cannot be modified. In that case, you need to delete the attachment and create it again.


Importing via XML/JSON

Importing attachments via XML is also supported (the data must again be Base64-encoded), but this has certain limitations:

  • a new attachment can only be created as part of another object (it cannot be the root tag)

  • only the metadata can be changed, not the attachment data itself

Use a different endpoint URL than the one used for importing a binary file, e.g.: /c/firma/faktura-vydana.xml.

XML example

<winstrom>
<faktura-vydana>
<id>11925</id>
<prilohy>
<priloha update="ignore">
<id>ext:DPH-KONTROLA:faktura-vydana:11925</id>
<contentType>text/html</contentType>
<nazSoub>vies-CZ18239617-2023-01-19.html</nazSoub>
<typK>typPrilohy.ostatni</typK>
<content encoding="base64">PGh0bWw+PG...</content>
</priloha>
</prilohy>
</faktura-vydana>
</winstrom>

JSON example

{
"winstrom": {
"faktura-vydana": {
"id": "11925",
"prilohy": {
"priloha": {
"id": "ext:DPH-KONTROLA:faktura-vydana:11925",
"contentType": "text/html",
"nazSoub": "vies-CZ18239617-2023-01-19.html",
"typK": "typPrilohy.ostatni",
"content@encoding": "base64",
"content": "PGh0bWw+PG..."
}
}
}
}
}

ℹ️ If you import an XML attachment, the API automatically switches to XML communication format (it then ignores the JSON header).


Exporting to XML

The content of an attachment can also be exported directly to XML; the data is exported Base64-encoded (<content encoding="base64">...</content>).

When accessed via the REST API, attachments can also be exported as part of the objects they belong to; in that case, you need to include the relations=prilohy parameter in the URL.


Image support

If you upload an attachment in image format to ABRA Flexi, support for generating thumbnails is added. The image must be in one of these formats:

  • image/jpeg

  • image/gif

  • image/png

For objects with an attachment, you can request the primary image (if none exists, the response will be a 404 error):

/c/firma/cenik/12/thumbnail.png

You can specify the image size using the w and h parameters, for example ?w=64&h=64.


Settings attachments

The company settings contain two attachments: the logo and the signature and stamp. These are handled in a special way.

Checking whether a logo is attached

GET /c/firma/nastaveni/1/logo

If a logo is attached, a redirect to the canonical URL of the attachment is returned (in the form /c/firma/priloha/3), i.e., status code 303 and header Location. If no logo is attached, status code 404 is returned.

Attaching a logo

If no logo is attached, you can attach one by calling PUT or POST (with the correct Content-Type header):

PUT /c/firma/nastaveni/1/logo 
Content-Type: image/jpeg

As usual, the logo's binary data must be included in the request body. Success is indicated by status code 201, and the URL of the newly created attachment is provided in the Location header.

⚠️ Just as with attachments, you cannot attach a logo to the settings if a logo is already attached. In that case, error code 400 is returned.

Removing a logo

DELETE /c/firma/nastaveni/1/logo

If the logo was successfully removed, status code 200 is returned. If no logo existed, error code 404 is returned.

ℹ️ The signature and stamp are handled in exactly the same way, except that instead of the word logo, you use podpis-razitko in the URL (e.g., /c/firma/nastaveni/1/podpis-razitko).

Did this answer your question?