2525
2626from ..error import OneDriveError
2727from ..model .upload_session import UploadSession
28+ from ..model .item import Item
2829from ..options import HeaderOption
2930from ..request .item_request_builder import ItemRequestBuilder
3031from ..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