Skip to main content

Creating an Attachment for a Record Using cURL

How do I use cURL to add an attachment to a record

Written by Petr Pech

You can add an attachment to any record with a single PUT request to the prilohy sub-evidence. Below is an example of how to attach an image to a price list item using the cURL tool.


Command

curl -u uzivatel:heslo -k -L -X PUT \
-H "Content-Type: image/jpeg" \
-T "C:\obrazky\LAMPA1.jpg" \
"https://server:5434/c/{firma}/cenik/code:LAMPA1/prilohy/new/LAMPA1.jpg"

Individual parts of the command:

Command part

Meaning

cenik/code:LAMPA1

The record to which the attachment is being added. Besides the internal ID, you can also use a code or external identifier — in that case you need to use -L, since the server responds with a redirect.

prilohy/new/LAMPA1.jpg

The last part of the address is saved as the attachment's file name (property nazSoub). It does not need to match the file name on disk.

-T

The file on disk that is sent as the request body.

-H "Content-Type: …"

The content type. If you don't specify it, the attachment will be saved with the type content/unknown.

A successful upload returns 201. You can list a record's attachments at the address /c/{firma}/cenik/code:LAMPA1/prilohy.xml, and view the content of a specific attachment at /prilohy/{ID}/content.

📝 cURL is a freely available program — it comes built into Windows, macOS, and most Linux distributions. On Windows, be careful with backslashes in the path: they work inside double quotes, but in PowerShell it's safer to use regular forward slashes.


Related

Did this answer your question?