-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathupload.py
More file actions
22 lines (18 loc) · 724 Bytes
/
Copy pathupload.py
File metadata and controls
22 lines (18 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
Demonstrates how to upload small files (up to 4MB in size).
See https://learn.microsoft.com/en-us/sharepoint/dev/apis/rest-api/navigation/file-operations
"""
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, password, site_url, tenant, username
ctx = ClientContext(site_url).with_username_and_password(
tenant=tenant,
client_id=client_id,
username=username,
password=password,
)
list_title = "Documents"
folder = ctx.web.lists.get_by_title(list_title).root_folder
path = "../../data/Financial Sample.xlsx"
with open(path, "rb") as f:
file = folder.files.upload(f).execute_query()
print(f"File has been uploaded into: {file.server_relative_url}")