How to add custom meta data to your documents on Nextcloud

Mathias Conradt
2 min readNov 25, 2017

Nextcloud is a leading open-source file sync and sharing platform. It comes with a nice web client, desktop sync client as well as mobile clients. Having worked in the document management field for quite a while (using Alfresco and Nuxeo before), I came across multiple use-cases where users wanted to assign some meta data to documents in order to classify them a bit more or add simple workflow information to it, especially when using the file sharing and sync integrated into their own custom web application via API.

Did you know that this is also possible with Nextcloud out of the box? Since Nextcloud uses the WebDAV protocol via https, you could easily make use of WebDAVs custom properties feature and assign such custom meta data to it via simple REST calls.

My standard use-case that I always use as an example is invoice management: Being able to add customer number, invoice number, invoice date, amount to a document.

Here is an example:

SETTING/UPDATING A CUSTOM PROPERTY (which did’t exist before):

curl -u ‘username:password’ ‘https://mynextcloud/remote.php/dav/files/mathias/Invoices/IncomingInvoice.pdf' -X PROPPATCH — data ‘<?xml version=”1.0"?><d:propertyupdate xmlns:d=”DAV:” xmlns:oc=”http://owncloud.org/ns"><d:set><d:prop><oc:invoicenumber>INV 06–20171112–01</oc:invoicenumber></d:prop></d:set></d:propertyupdate>’

READING A DOCUMENT WITH CUSTOM PROPERTY:

curl -u ‘username:password’ ‘https://mynextcloud/remote.php/dav/files/mathias/Invoices/IncomingInvoice.pdf' -X PROPFIND — data ‘<?xml version=”1.0" encoding=”UTF-8"?><d:propfind xmlns:d=”DAV:”><d:prop xmlns:oc=”http://owncloud.org/ns"><d:getlastmodified/><d:getcontentlength/><d:getcontenttype/><oc:permissions/><oc:invoicenumber/><d:resourcetype/><d:getetag/></d:prop></d:propfind>'

Response:

<?xml version=”1.0" ?>
<d:multistatus xmlns:cal=”urn:ietf:params:xml:ns:caldav” xmlns:card=”urn:ietf:params:xml:ns:carddav” xmlns:cs=”http://calendarserver.org/ns/" xmlns:d=”DAV:” xmlns:nc=”http://nextcloud.org/ns" xmlns:oc=”http://owncloud.org/ns" xmlns:s=”http://sabredav.org/ns">
<d:response>
<d:href>/remote.php/dav/files/mathias/Invoices/IncomingInvoice.pdf</d:href>
<d:propstat>
<d:prop>
<d:getlastmodified>Thu, 09 Nov 2017 08:28:58 GMT</d:getlastmodified>
<d:getcontentlength>28</d:getcontentlength>
<d:getcontenttype>application/pdf</d:getcontenttype>
<oc:permissions>RDNVW</oc:permissions>
<oc:invoicenumber>INV 06–20171112–01</oc:invoicenumber>
<d:resourcetype/>
<d:getetag>”3603cfc90e6db167380fbd524b9af0f3"</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>

One thing to note: the custom property fields are not type-safe and validation should be handled by whatever client application you use to talk to the Nextcloud/WebDAV repository.

Also: Custom meta added as described above doesn’t appear automatically in the Nextcloud web UI, but it’s especially useful when Nextcloud is used as a “headless” document repository integrated in a custom business application, which were my main use-cases in past projects.

--

--

Mathias Conradt

Cybersecurity Professional | Staff Solutions Engineer at Snyk | DevSecCon Germany Chapter Lead | Motorbiker & MotoGP Fan | Tactical & Stealth Gamer