-
-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathupload_large.py
More file actions
32 lines (24 loc) · 961 Bytes
/
upload_large.py
File metadata and controls
32 lines (24 loc) · 961 Bytes
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
32
"""
Demonstrates how to upload large file
"""
import os
from office365.sharepoint.client_context import ClientContext
from tests import test_team_site_url, test_user_credentials
def print_upload_progress(offset):
# type: (int) -> None
file_size = os.path.getsize(local_path)
print(
"Uploaded '{0}' bytes from '{1}'...[{2}%]".format(
offset, file_size, round(offset / file_size * 100, 2)
)
)
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
target_url = "Shared Documents/archive"
target_folder = ctx.web.get_folder_by_server_relative_url(target_url)
size_chunk = 1000000
local_path = "../../../tests/data/big_buck_bunny.mp4"
with open(local_path, "rb") as f:
uploaded_file = target_folder.files.create_upload_session(
f, size_chunk, print_upload_progress
).execute_query()
print("File {0} has been uploaded successfully".format(uploaded_file.serverRelativeUrl))