Skip to content

Commit 50b6b36

Browse files
authored
Merge pull request #94 from clowder-framework/93-allow-folder-in-upload-file-to-dataset
93 allow folder in upload file to dataset
2 parents 48a08ef + 4ef4685 commit 50b6b36

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](https://semver.org/).
77

8+
- ## 3.0.6 - 2023-10-09
9+
10+
### Added
11+
12+
- Allow folder id to be passed to api/v2 upload_to_dataset
13+
814
- ## 3.0.5 - 2023-10-09
915

1016
### Added

pyclowder/api/v2/files.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,15 @@ def upload_thumbnail(connector, client, fileid, thumbnail):
324324
logger.error("unable to upload thumbnail %s to file %s", thumbnail, fileid)
325325

326326

327-
def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=False):
327+
def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=False, folder_id=None):
328328
"""Upload file to existing Clowder dataset.
329329
330330
Keyword arguments:
331331
connector -- connector information, used to get missing parameters and send status updates
332332
client -- ClowderClient containing authentication credentials
333333
datasetid -- the dataset that the file should be associated with
334334
filepath -- path to file
335+
folder_id -- the folder that the file should be uploaded to
335336
check_duplicate -- check if filename already exists in dataset and skip upload if so
336337
"""
337338

@@ -349,6 +350,8 @@ def upload_to_dataset(connector, client, datasetid, filepath, check_duplicate=Fa
349350
return _upload_to_dataset_local(connector, client, datasetid, filepath)
350351

351352
url = '%s/api/v2/datasets/%s/files' % (client.host, datasetid)
353+
if folder_id is not None:
354+
url = '%s?folder_id=%s' % (url, folder_id)
352355

353356
if os.path.exists(filepath):
354357
filename = os.path.basename(filepath)

pyclowder/files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def upload_thumbnail(connector, host, key, fileid, thumbnail):
256256
return thumbnail_id
257257

258258

259-
def upload_to_dataset(connector, host, key, datasetid, filepath, check_duplicate=False):
259+
def upload_to_dataset(connector, host, key, datasetid, filepath, check_duplicate=False, folder_id=None):
260260
"""Upload file to existing Clowder dataset.
261261
262262
Keyword arguments:
@@ -266,10 +266,11 @@ def upload_to_dataset(connector, host, key, datasetid, filepath, check_duplicate
266266
datasetid -- the dataset that the file should be associated with
267267
filepath -- path to file
268268
check_duplicate -- check if filename already exists in dataset and skip upload if so
269+
folder_id -- the folder that the file should be associated with
269270
"""
270271
client = ClowderClient(host=host, key=key)
271272
if clowder_version == 2:
272-
return files.upload_to_dataset(connector, client, datasetid, filepath, check_duplicate)
273+
return files.upload_to_dataset(connector, client, datasetid, filepath, check_duplicate, folder_id)
273274
else:
274275
logger = logging.getLogger(__name__)
275276

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='pyclowder',
11-
version='3.0.5',
11+
version='3.0.6',
1212
description='Python SDK for the Clowder Data Management System',
1313
long_description=long_description,
1414

0 commit comments

Comments
 (0)