Attaching metadata to a file does not work
The code snippet below should assign a metadata field type
to the uploaded file setup.py
, but instead adds an archive-level property type:setup.py
.
Output:
{
...
'files': [
{
...
'meta': {},
'name': 'test.py',
...
}
],
...
'meta': {
'collection': ['The Collection'],
'type:test.py': ['thumbnail']
},
...
}
import pathlib
from pycdstar3.client import CDStar, FormUpdate
URL = "https://cdstar.gwdg.de/demo/v3/"
USER = "test"
PWD = "test"
if __name__ == "__main__":
api = CDStar(URL, auth=(USER, PWD))
with api.begin(autocommit=True) as tx:
res = api.service_info()
vault = res['vaults'][0]
res = api.create_archive(vault)
archive = res['id']
p = pathlib.Path(__file__)
with p.open('rb') as fp:
res = api.put_file(vault, archive, '/' + p.name, fp)
md = FormUpdate()
md.meta('type', 'thumbnail', target=res['name'])
api.update_archive(vault, archive, md)
md = FormUpdate()
md.meta('collection', 'The Collection')
api.update_archive(vault, archive, md)
print(api.GET(vault, archive, params=[('with', 'meta'), ('with', 'files')]))