Skip to content

Commit 515354d

Browse files
author
Eric Mugnier
committed
Adding option to set file created and last modified time while uploading
1 parent 1e2708e commit 515354d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

O365/drive.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,15 @@ def upload_file(self, item, item_name=None, chunk_size=DEFAULT_UPLOAD_CHUNK_SIZE
12911291
self._endpoints.get('create_upload_session').format(
12921292
id=self.object_id, filename=quote(item.name if item_name is None else item_name)))
12931293

1294-
# If not None, add conflict handling to request
1294+
# WARNING : order matters in the dict, first we need to set conflictBehavior (if any) and then createdDateTime, otherwise microsoft refuses the api
1295+
# call...
12951296
file_data = {}
12961297
if conflict_handling:
1297-
file_data["item"] = {"@microsoft.graph.conflictBehavior": conflict_handling}
1298+
file_data.setdefault("item", dict())["@microsoft.graph.conflictBehavior"] = conflict_handling
1299+
if file_created_date_time:
1300+
file_data.setdefault("item", dict()).setdefault("fileSystemInfo", dict())["createdDateTime"] = file_created_date_time
1301+
if file_last_modified_date_time:
1302+
file_data.setdefault("item", dict()).setdefault("fileSystemInfo", dict())["lastModifiedDateTime"] = file_last_modified_date_time
12981303

12991304
response = self.con.post(url, data=file_data)
13001305
if not response:

0 commit comments

Comments
 (0)