@@ -960,17 +960,6 @@ public async Task<OneDriveItem> UploadFileViaResumableUpload(string filePath, st
960960 return await UploadFileViaResumableUpload ( file , fileName , oneDriveItem , null , nameConflictBehavior ) ;
961961 }
962962
963- /// <summary>
964- /// Initiates a resumable upload session to OneDrive. It doesn't perform the actual upload yet.
965- /// </summary>
966- /// <param name="fileName">Filename to store the uploaded content under</param>
967- /// <param name="oneDriveItem">OneDriveItem container in which the file should be uploaded</param>
968- /// <returns>OneDriveUploadSession instance containing the details where to upload the content to</returns>
969- protected override async Task < OneDriveUploadSession > CreateResumableUploadSession ( string fileName , OneDriveItem oneDriveItem )
970- {
971- return await CreateResumableUploadSession ( fileName , oneDriveItem , NameConflictBehavior . Replace ) ;
972- }
973-
974963 /// <summary>
975964 /// Initiates a resumable upload session to OneDrive. It doesn't perform the actual upload yet.
976965 /// </summary>
@@ -1042,6 +1031,101 @@ protected override async Task<OneDriveItem> UploadFileViaResumableUploadInternal
10421031 return await base . UploadFileViaResumableUploadInternal ( fileStream , oneDriveUploadSession , fragmentSizeInBytes ?? ResumableUploadChunkSizeInBytes ) ;
10431032 }
10441033
1034+ /// <summary>
1035+ /// Initiates a resumable upload session to OneDrive to overwrite an existing file. It doesn't perform the actual upload yet.
1036+ /// </summary>
1037+ /// <param name="oneDriveItem">OneDriveItem item for which updated content will be uploaded</param>
1038+ /// <returns>OneDriveUploadSession instance containing the details where to upload the content to</returns>
1039+ protected override async Task < OneDriveUploadSession > CreateResumableUploadSession ( OneDriveItem oneDriveItem )
1040+ {
1041+ // Construct the complete URL to call
1042+ string completeUrl ;
1043+ if ( oneDriveItem . RemoteItem != null )
1044+ {
1045+ // Item will be uploaded to another drive
1046+ completeUrl = string . Concat ( "drives/" , oneDriveItem . RemoteItem . ParentReference . DriveId , "/items/" , oneDriveItem . RemoteItem . Id , "/createUploadSession" ) ;
1047+ }
1048+ else if ( oneDriveItem . ParentReference != null && ! string . IsNullOrEmpty ( oneDriveItem . ParentReference . DriveId ) )
1049+ {
1050+ // Item will be uploaded to another drive
1051+ completeUrl = string . Concat ( "drives/" , oneDriveItem . ParentReference . DriveId , "/items/" , oneDriveItem . Id , "/createUploadSession" ) ;
1052+ }
1053+ else if ( ! string . IsNullOrEmpty ( oneDriveItem . WebUrl ) && oneDriveItem . WebUrl . Contains ( "cid=" ) )
1054+ {
1055+ // Item will be uploaded to another drive. Used by OneDrive Personal when using a shared item.
1056+ completeUrl = string . Concat ( "drives/" , oneDriveItem . WebUrl . Remove ( 0 , oneDriveItem . WebUrl . IndexOf ( "cid=" ) + 4 ) , "/items/" , oneDriveItem . Id , "/createUploadSession" ) ;
1057+ }
1058+ else
1059+ {
1060+ // Item will be uploaded to the current user its drive
1061+ completeUrl = string . Concat ( "drive/items/" , oneDriveItem . Id , "/createUploadSession" ) ;
1062+ }
1063+
1064+ completeUrl = ConstructCompleteUrl ( completeUrl ) ;
1065+
1066+ // Construct the OneDriveUploadSessionItemContainer entity with the upload details
1067+ // Add the conflictbehavior header to always overwrite the file if it already exists on OneDrive
1068+ var uploadItemContainer = new OneDriveUploadSessionItemContainer
1069+ {
1070+ Item = new OneDriveUploadSessionItem
1071+ {
1072+ FilenameConflictBehavior = NameConflictBehavior . Replace
1073+ }
1074+ } ;
1075+
1076+ // Call the OneDrive webservice
1077+ var result = await SendMessageReturnOneDriveItem < OneDriveUploadSession > ( uploadItemContainer , HttpMethod . Post , completeUrl , HttpStatusCode . OK ) ;
1078+ return result ;
1079+ }
1080+
1081+ /// <summary>
1082+ /// Initiates a resumable upload session to OneDrive. It doesn't perform the actual upload yet.
1083+ /// </summary>
1084+ /// <param name="fileName">Filename to store the uploaded content under</param>
1085+ /// <param name="oneDriveFolder">OneDriveItem container in which the file should be uploaded</param>
1086+ /// <returns>OneDriveUploadSession instance containing the details where to upload the content to</returns>
1087+ protected override async Task < OneDriveUploadSession > CreateResumableUploadSession ( string fileName , OneDriveItem oneDriveFolder )
1088+ {
1089+ // Construct the complete URL to call
1090+ string completeUrl ;
1091+ if ( oneDriveFolder . RemoteItem != null )
1092+ {
1093+ // Item will be uploaded to another drive
1094+ completeUrl = string . Concat ( "drives/" , oneDriveFolder . RemoteItem . ParentReference . DriveId , "/items/" , oneDriveFolder . RemoteItem . Id , ":/" , fileName , ":/createUploadSession" ) ;
1095+ }
1096+ else if ( oneDriveFolder . ParentReference != null && ! string . IsNullOrEmpty ( oneDriveFolder . ParentReference . DriveId ) )
1097+ {
1098+ // Item will be uploaded to another drive
1099+ completeUrl = string . Concat ( "drives/" , oneDriveFolder . ParentReference . DriveId , "/items/" , oneDriveFolder . Id , ":/" , fileName , ":/createUploadSession" ) ;
1100+ }
1101+ else if ( ! string . IsNullOrEmpty ( oneDriveFolder . WebUrl ) && oneDriveFolder . WebUrl . Contains ( "cid=" ) )
1102+ {
1103+ // Item will be uploaded to another drive. Used by OneDrive Personal when using a shared item.
1104+ completeUrl = string . Concat ( "drives/" , oneDriveFolder . WebUrl . Remove ( 0 , oneDriveFolder . WebUrl . IndexOf ( "cid=" ) + 4 ) , "/items/" , oneDriveFolder . Id , ":/" , fileName , ":/createUploadSession" ) ;
1105+ }
1106+ else
1107+ {
1108+ // Item will be uploaded to the current user its drive
1109+ completeUrl = string . Concat ( "drive/items/" , oneDriveFolder . Id , ":/" , fileName , ":/createUploadSession" ) ;
1110+ }
1111+
1112+ completeUrl = ConstructCompleteUrl ( completeUrl ) ;
1113+
1114+ // Construct the OneDriveUploadSessionItemContainer entity with the upload details
1115+ // Add the conflictbehavior header to always overwrite the file if it already exists on OneDrive
1116+ var uploadItemContainer = new OneDriveUploadSessionItemContainer
1117+ {
1118+ Item = new OneDriveUploadSessionItem
1119+ {
1120+ FilenameConflictBehavior = NameConflictBehavior . Replace
1121+ }
1122+ } ;
1123+
1124+ // Call the OneDrive webservice
1125+ var result = await SendMessageReturnOneDriveItem < OneDriveUploadSession > ( uploadItemContainer , HttpMethod . Post , completeUrl , HttpStatusCode . OK ) ;
1126+ return result ;
1127+ }
1128+
10451129 #endregion
10461130
10471131 /// <summary>
0 commit comments