Skip to content

Commit bc71fab

Browse files
committed
OneDrive examples: download a large file
1 parent 6e95d01 commit bc71fab

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import tempfile
3+
4+
from examples import acquire_token_by_username_password
5+
from office365.graph_client import GraphClient
6+
from office365.onedrive.driveitems.driveItem import DriveItem
7+
8+
client = GraphClient(acquire_token_by_username_password)
9+
# 1. address file by path and get file metadata
10+
file_item = client.me.drive.root.get_by_path("archive/Sample.rtf").get().execute_query() # type: DriveItem
11+
12+
# 2. download file content
13+
with tempfile.TemporaryDirectory() as local_path:
14+
with open(os.path.join(local_path, file_item.name), 'wb') as local_file:
15+
file_item.download(local_file).execute_query()
16+
print("File '{0}' has been downloaded into {1}".format(file_item.name, local_file.name))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import tempfile
3+
4+
from examples import acquire_token_by_username_password
5+
from office365.graph_client import GraphClient
6+
from office365.onedrive.driveitems.driveItem import DriveItem
7+
8+
9+
def print_download_progress(offset):
10+
print("Downloaded '{0}' bytes...".format(offset))
11+
12+
13+
client = GraphClient(acquire_token_by_username_password)
14+
# # 1. address file by path and get file metadata
15+
file_item = client.me.drive.root.get_by_path("archive/big_buck_bunny.mp4").get().execute_query() # type: DriveItem
16+
# 2 download a large file (chunked file download)
17+
with tempfile.TemporaryDirectory() as local_path:
18+
with open(os.path.join(local_path, file_item.name), 'wb') as local_file:
19+
file_item.download_session(local_file, print_download_progress).execute_query()
20+
print("File '{0}' has been downloaded into {1}".format(file_item.name, local_file.name))

examples/sharepoint/connect_with_client_certificate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
cert_settings = {
66
'client_id': '51d03106-4726-442c-86db-70b32fa7547f',
77
'thumbprint': "61C754D8D9629BE91972B6A0C1999DC678FB0145",
8-
'cert_path': '{0}/selfsigncert.pem'.format(os.path.dirname(__file__))
8+
'cert_path': '{0}/selfsigncert.pem'.format(os.path.dirname(__file__)),
9+
'scopes': ['{0}.default'.format(test_site_url)]
910
}
1011

1112
ctx = ClientContext(test_site_url).with_client_certificate(test_tenant, **cert_settings)

0 commit comments

Comments
 (0)