forked from vgrem/Office365-REST-Python-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.py
31 lines (26 loc) · 1007 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
28
29
30
31
"""
Demonstrates how to upload files from a local folder into OneDrive drive
"""
import os
from os.path import isfile, join
from office365.graph_client import GraphClient
from office365.runtime.client_request_exception import ClientRequestException
from tests.graph_case import acquire_token_by_username_password
client = GraphClient(acquire_token_by_username_password)
remote_drive = client.me.drive
local_path = "../../data"
for name in os.listdir(local_path):
path = join(local_path, name)
if isfile(path):
try:
with open(path, "rb") as local_file:
uploaded_file = remote_drive.root.upload_file(
local_file
).execute_query()
print("File '{0}' uploaded into '{1}'".format(path, uploaded_file.web_url))
except ClientRequestException as e:
print(
"An error occured while uploading a file {0}: {1}".format(
path, e.message
)
)