Skip to content

Commit 67bfe2d

Browse files
feat: example to upload file to SystemLink (#81)
1 parent 9afac65 commit 67bfe2d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

docs/getting_started.rst

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ Get the metadata of a File using its Id and download it.
212212
:language: python
213213
:linenos:
214214

215+
Upload a File from disk or memory to SystemLink
216+
217+
.. literalinclude:: ../examples/file/upload_file.py
218+
215219
Feeds API
216220
-------
217221

examples/file/upload_file.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Example to upload a file to SystemLink."""
2+
3+
import io
4+
5+
from nisystemlink.clients.file import FileClient
6+
7+
client = FileClient()
8+
9+
workspace_id = None # Upload to default workspace of the auth key
10+
11+
# Upload file from disk
12+
file_path = "path/to/your/file"
13+
with open(file_path, "rb") as fp:
14+
file_id = client.upload_file(file=fp, workspace=workspace_id)
15+
print(f"Uploaded file from {file_path} to SystemLink with FileID - {file_id}")
16+
17+
# Upload file-like object from memory
18+
test_file = io.BytesIO(b"This is an example file content.")
19+
test_file.name = "File_From_Memory.txt" # assign a name to the file object
20+
file_id = client.upload_file(file=test_file)
21+
print(f"Uploaded file from memory to SystemLink with FileID - {file_id}")

0 commit comments

Comments
 (0)