Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on which PR merged in first, i can bump the version


### Added

- Allow folder id to be passed to api/v2 upload_to_dataset

- ## 3.0.5 - 2023-10-09

### Added
Expand Down
5 changes: 4 additions & 1 deletion pyclowder/api/v2/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,15 @@ 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:
connector -- connector information, used to get missing parameters and send status updates
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
"""

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions pyclowder/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down