Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit f7a82a2

Browse files
committed
Add optional argument for name conflict resultion in fragment upload
1 parent 32a0105 commit f7a82a2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/onedrivesdk/extensions/fragment_upload.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from ..error import OneDriveError
2727
from ..model.upload_session import UploadSession
28+
from ..model.item import Item
2829
from ..options import HeaderOption
2930
from ..request.item_request_builder import ItemRequestBuilder
3031
from ..request_builder_base import RequestBuilderBase
@@ -128,11 +129,14 @@ def post_async(self, begin, length, options=None):
128129
return entity
129130

130131

131-
def fragment_upload(self, local_path, upload_status=None):
132+
def fragment_upload(self, local_path, conflict_behavior=None, upload_status=None):
132133
"""Uploads file using PUT using multipart upload if needed.
133134
134135
Args:
135136
local_path (str): The path to the local file to upload.
137+
conflict_behavior (str): conflict behavior if the file is already
138+
uploaded. Use None value if file should be replaced or "rename", if
139+
the new file should get a new name
136140
upload_status (func): function(current_part, total_parts) to be called
137141
with upload status for each 10MB part
138142
@@ -145,7 +149,12 @@ def fragment_upload(self, local_path, upload_status=None):
145149
return self.content.request().upload(local_path)
146150
else:
147151
# multipart upload needed for larger files
148-
session = self.create_session().post()
152+
if conflict_behavior:
153+
item = Item({'@name.conflictBehavior': conflict_behavior})
154+
else:
155+
item = Item({})
156+
157+
session = self.create_session(item).post()
149158

150159
with ItemUploadFragmentBuilder(session.upload_url, self._client, local_path) as upload_builder:
151160
total_parts = math.ceil(file_size / __PART_SIZE)

0 commit comments

Comments
 (0)