caterva2.upload#

caterva2.upload(localpath, dataset, urlbase=None, auth_cookie=None)#

Upload a local dataset to a remote repository.

Note: If localpath is a regular file (i.e. without a .b2nd, .b2frame or .b2 extension), it will be compressed with Blosc2 on the server side (i.e. it will have the .b2 extension appended internally, although this won’t be visible when using the web, API or CLI interfaces).

Parameters:
  • localpath (Path) – The path of the local dataset.

  • dataset (Path) – The remote path to upload the dataset to.

  • urlbase (str) – The base of URLs of the subscriber to query. Default is caterva2.sub_urlbase_default.

  • auth_cookie (str) – An HTTP cookie for authorizing access. This must be specified unless it was already specified inside a :py_obj:`caterva2.c2context`.

Returns:

The path of the uploaded file.

Return type:

Path

Examples

>>> import caterva2 as cat2
>>> import numpy as np
>>> # To upload a file you need to be authenticated as an already registered used
>>> urlbase = 'https://cat2.cloud/demo'
>>> auth_cookie = cat2.get_auth_cookie(urlbase, dict(username='user@example.com', password='foo'))
>>> newpath = f'@personal/dir{np.random.randint(0, 100)}/ds-4d.b2nd'
>>> uploaded_path = cat2.upload('root-example/dir2/ds-4d.b2nd', newpath, urlbase=urlbase, auth_cookie=auth_cookie)
>>> str(uploaded_path) == newpath
True