diff --git a/CHANGELOG.md b/CHANGELOG.md index 08abd71..f6674cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/). +- ## 3.0.6 - 2023-10-09 + +### Added + +- Allow folder id to be passed to api/v2 upload_to_dataset + - ## 3.0.5 - 2023-10-09 ### Added diff --git a/pyclowder/api/v2/files.py b/pyclowder/api/v2/files.py index c970ce4..7985a74 100644 --- a/pyclowder/api/v2/files.py +++ b/pyclowder/api/v2/files.py @@ -324,7 +324,7 @@ def upload_thumbnail(connector, client, fileid, thumbnail): logger.error("unable to upload thumbnail %s to file %s", thumbnail, fileid) -def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=False): +def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=False, folder_id=None): """Upload file to existing Clowder dataset. Keyword arguments: @@ -332,6 +332,7 @@ def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=Fa client -- ClowderClient containing authentication credentials datasetid -- the dataset that the file should be associated with filepath -- path to file + folder_id -- the folder that the file should be uploaded to check_duplicate -- check if filename already exists in dataset and skip upload if so """ @@ -349,6 +350,8 @@ def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=Fa return _upload_to_dataset_local(connector, client, datasetid, filepath) url = '%s/api/v2/datasets/%s/files' % (client.host, datasetid) + if folder_id is not None: + url = '%s?folder_id=%s' % (url, folder_id) if os.path.exists(filepath): filename = os.path.basename(filepath) diff --git a/pyclowder/files.py b/pyclowder/files.py index 3235722..b057781 100644 --- a/pyclowder/files.py +++ b/pyclowder/files.py @@ -256,7 +256,7 @@ def upload_thumbnail(connector, host, key, fileid, thumbnail): return thumbnail_id -def upload_to_dataset(connector, host, key, datasetid, filepath, check_duplicate=False): +def upload_to_dataset(connector, host, key, datasetid, filepath, check_duplicate=False, folder_id=None): """Upload file to existing Clowder dataset. Keyword arguments: @@ -266,10 +266,11 @@ def upload_to_dataset(connector, host, key, datasetid, filepath, check_duplicate datasetid -- the dataset that the file should be associated with filepath -- path to file check_duplicate -- check if filename already exists in dataset and skip upload if so + folder_id -- the folder that the file should be associated with """ client = ClowderClient(host=host, key=key) if clowder_version == 2: - return files.upload_to_dataset(connector, client, datasetid, filepath, check_duplicate) + return files.upload_to_dataset(connector, client, datasetid, filepath, check_duplicate, folder_id) else: logger = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index e757e98..746be90 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='pyclowder', - version='3.0.5', + version='3.0.6', description='Python SDK for the Clowder Data Management System', long_description=long_description,