pycdstar3 issueshttps://gitlab-ce.gwdg.de/cdstar/pycdstar3/-/issues2020-07-27T06:50:44Zhttps://gitlab-ce.gwdg.de/cdstar/pycdstar3/-/issues/2When uploading files, setting the type does not work.2020-07-27T06:50:44Zparciakmarcel.parciak@med.uni-goettingen.deWhen uploading files, setting the type does not work.I have observed that setting the MIME type of files does not work when uploading them using pycdstar3. I assume the error to be in `api.py` on on line 274, in the `put_file()` method of class `CDStar`:
```python
if isinstance(source, PA...I have observed that setting the MIME type of files does not work when uploading them using pycdstar3. I assume the error to be in `api.py` on on line 274, in the `put_file()` method of class `CDStar`:
```python
if isinstance(source, PATH_TYPES):
with open(source, "rb") as source:
return self.put_file(
vault, archive, name, source, type=None, replace=True
)
```
When `put_file` calls itself upon finding a path, type and replace are set to the default values regardless of any values set when calling the method. I changed that to:
```python
if isinstance(source, PATH_TYPES):
with open(source, "rb") as source:
return self.put_file(
vault, archive, name, source, type=type, replace=replace
)
```
Works like a charm now.https://gitlab-ce.gwdg.de/cdstar/pycdstar3/-/issues/1Attaching metadata to a file does not work2019-10-07T13:14:19ZrforkelAttaching metadata to a file does not workThe 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:
```python
{
...
'files': [
{
...
'...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:
```python
{
...
'files': [
{
...
'meta': {},
'name': 'test.py',
...
}
],
...
'meta': {
'collection': ['The Collection'],
'type:test.py': ['thumbnail']
},
...
}
```
```python
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')]))
```