caterva2.upload#

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

Uploads a local dataset to a remote repository.

Note: If localpath is a regular file without a .b2nd, .b2frame or .b2 extension, it will be automatically compressed with Blosc2 on the server, adding a .b2 extension internally.

Parameters:
  • localpath (Path) – Path to the local dataset.

  • dataset (Path) – Remote path to upload the dataset to.

  • urlbase (str, optional) – Base URL to query. Default to caterva2.sub_urlbase_default.

  • auth_cookie (str, optional) – HTTP cookie for authorization. Must be provided unless already set in a :py_obj:`caterva2.c2context`.

Returns:

Path of the uploaded file on ther server.

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, auth_cookie)
>>> str(uploaded_path) == newpath
True