Skip to content

Commit 1995df4

Browse files
authored
Merge pull request #289 from beliaev-maksim/beliaev_args_upload
added possibility to specify args for upload report functions
2 parents e6c99e1 + 026e331 commit 1995df4

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

examples/sharepoint/files/upload_large_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from office365.sharepoint.client_context import ClientContext
77

88

9-
def print_upload_progress(offset):
10-
print("Uploaded '{0}' bytes...".format(offset))
9+
def print_upload_progress(offset, total_size):
10+
print("Uploaded '{}' bytes from '{}'...[{}%]".format(offset, total_size, round(offset/total_size*100, 2)))
1111

1212

1313
credentials = UserCredential(settings['user_credentials']['username'],
@@ -18,7 +18,7 @@ def print_upload_progress(offset):
1818
target_folder = ctx.web.get_folder_by_server_relative_url(target_url)
1919
size_chunk = 1000000
2020
local_path = "../../../tests/data/big_buck_bunny.mp4"
21-
# local_path = "../../../tests/data/SharePoint User Guide.docx"
21+
2222
file_size = os.path.getsize(local_path)
2323

2424
if file_size > size_chunk:

office365/sharepoint/actions/upload_session.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _create_empty_file(path):
2525

2626

2727
class UploadSessionQuery(CreateFileQuery):
28-
def __init__(self, files, source_path, chunk_size, chunk_uploaded):
28+
def __init__(self, files, source_path, chunk_size, chunk_uploaded, chunk_func_args):
2929
"""
3030
3131
:type files: office365.sharepoint.files.file_collection.FileCollection
@@ -39,6 +39,7 @@ def __init__(self, files, source_path, chunk_size, chunk_uploaded):
3939
self._upload_id = str(uuid.uuid4())
4040
self._source_path = source_path
4141
self._chunk_uploaded = chunk_uploaded
42+
self._chunk_func_args = chunk_func_args
4243
self._uploaded_bytes = 0
4344
self._upload_results = []
4445
self.file.context.after_execute(self._build_upload_session_query)
@@ -70,7 +71,7 @@ def _process_chunk_upload(self, resp):
7071
self.file.context.after_execute(self._process_chunk_upload)
7172
elif isinstance(self._return_type, File):
7273
self._uploaded_bytes = qry.return_type.length
73-
self._chunk_uploaded(self._uploaded_bytes)
74+
self._chunk_uploaded(self._uploaded_bytes, *self._chunk_func_args)
7475

7576
@property
7677
def file(self):

office365/sharepoint/files/file_collection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ def get(self):
1919
"""
2020
return super(FileCollection, self).get()
2121

22-
def create_upload_session(self, source_path, chunk_size, chunk_uploaded=None):
22+
def create_upload_session(self, source_path, chunk_size, chunk_uploaded=None, *chunk_func_args):
2323
"""Upload a file as multiple chunks
2424
2525
:param str source_path: path where file to upload resides
2626
:param int chunk_size: upload chunk size
2727
:param (long)->None or None chunk_uploaded: uploaded event
28+
:param chunk_func_args: arguments to pass to chunk_uploaded function
2829
:return: office365.sharepoint.files.file.File
2930
"""
30-
qry = UploadSessionQuery(self, source_path, chunk_size, chunk_uploaded)
31+
qry = UploadSessionQuery(self, source_path, chunk_size, chunk_uploaded, chunk_func_args)
3132
self.context.add_query(qry)
3233
return qry.file
3334

0 commit comments

Comments
 (0)