-
-
Notifications
You must be signed in to change notification settings - Fork 352
/
Copy pathupload.py
27 lines (23 loc) · 847 Bytes
/
upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Demonstrates how to upload a small file
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests import (
test_client_id,
test_client_secret,
test_tenant,
test_user_principal_name_alt,
)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)
user_drive = client.users.get_by_principal_name(test_user_principal_name_alt).drive
folder = user_drive.root
local_path = "../../data/Financial Sample.xlsx"
# local_path = "../../data/countries.json"
# file = folder.upload_file(local_path).execute_query()
with open(local_path, "rb") as f:
file = folder.upload_file(f).execute_query()
print("File {0} has been uploaded".format(file.web_url))
result = folder.children.get().execute_query()