From b41c5eb05d8b7e4cadd5a6dc3811a7aaa088780a Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 17 Jul 2019 05:11:38 +1000 Subject: [PATCH] Update Sharepoint modified file handling for files > 4Mb in size (#594) * Update Sharepoint modified file handling for files > 4Mb in size --- src/sync.d | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sync.d b/src/sync.d index 4b10cb36..e2ecc919 100644 --- a/src/sync.d +++ b/src/sync.d @@ -2296,8 +2296,22 @@ final class SyncEngine // OneDrive SharePoint account modified file upload handling if (accountType == "documentLibrary"){ - // We cant use a session to upload the file, we have to use simpleUploadReplace - response = onedrive.simpleUploadReplace(path, fileDetailsFromOneDrive["parentReference"]["driveId"].str, fileDetailsFromOneDrive["id"].str, fileDetailsFromOneDrive["eTag"].str); + // Depending on the file size, this will depend on how best to handle the modified local file + // as if too large, the following error will be generated by OneDrive: + // HTTP request returned status code 413 (Request Entity Too Large) + // We also cant use a session to upload the file, we have to use simpleUploadReplace + + if (getSize(path) <= thresholdFileSize) { + // Upload file via simpleUploadReplace as below threshhold size + response = onedrive.simpleUploadReplace(path, fileDetailsFromOneDrive["parentReference"]["driveId"].str, fileDetailsFromOneDrive["id"].str, fileDetailsFromOneDrive["eTag"].str); + } else { + // Have to upload via a session, however we have to delete the file first otherwise this will generate a 404 error post session upload + // Remove the existing file + onedrive.deleteById(fileDetailsFromOneDrive["parentReference"]["driveId"].str, fileDetailsFromOneDrive["id"].str, fileDetailsFromOneDrive["eTag"].str); + // Upload as a session, as a new file + writeln(""); + response = session.upload(path, parent.driveId, parent.id, baseName(path)); + } writeln(" done."); saveItem(response); // Due to https://github.com/OneDrive/onedrive-api-docs/issues/935 Microsoft modifies all PDF, MS Office & HTML files with added XML content. It is a 'feature' of SharePoint.