Skip to content

Commit 3777830

Browse files
committed
add download example in 03
1 parent 5a381d3 commit 3777830

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

examples/03.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import os
23
import time
34
import datetime
45
import elabapi_python
@@ -38,6 +39,13 @@
3839
# display id, name and comment of the uploaded files
3940
for upload in uploadsApi.read_uploads('experiments', exp.id):
4041
print(upload.id, upload.real_name, upload.comment)
42+
# get and save file
43+
with open(f'README.downloaded_with_api.md', 'wb') as file:
44+
# the _preload_content flag is necessary so the api_client doesn't try and deserialize the response
45+
file.write(uploadsApi.read_upload('experiments', 256, upload.id, format='binary', _preload_content=False).data)
4146
# delete all the files where the name is 'README.md'
4247
if upload.real_name == 'README.md':
4348
uploadsApi.delete_upload('experiments', 256, upload.id)
49+
50+
# cleanup: delete the downloaded file
51+
os.remove('README.downloaded_with_api.md')

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Look for all items of a particular category and patch the metadata if it is empt
1616

1717
# 03.py
1818

19-
Upload and delete a file in an experiment.
19+
Upload, download and delete a file in an experiment.
2020

2121
# 04.py
2222

0 commit comments

Comments
 (0)