Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 3fac9b6

Browse files
committed
Version 2.3.0.2
1 parent fbafdcb commit 3fac9b6

File tree

4 files changed

+116
-23
lines changed

4 files changed

+116
-23
lines changed

Api/API.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
<AssemblyName>KoenZomers.OneDrive.Api</AssemblyName>
66
<SignAssembly>true</SignAssembly>
77
<AssemblyOriginatorKeyFile>KoenZomers.OneDrive.Api.snk</AssemblyOriginatorKeyFile>
8-
<Version>2.3.0.1</Version>
8+
<Version>2.3.0.2</Version>
99
<Authors>Koen Zomers</Authors>
1010
<Company>Koen Zomers</Company>
1111
<Description>API in .NET Standard 2.0, .NET Framework 4.5.2, .NET Framework 4.7.2 and .NET Core 2.0 to communicate with OneDrive Personal and OneDrive for Business</Description>
1212
<PackageProjectUrl>https://github.com/KoenZomers/OneDriveAPI</PackageProjectUrl>
1313
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
14-
<PackageReleaseNotes>- Recompiled to support multi platform to support .NET Standard 2.0, .NET Framework 4.5.2, .NET Framework 4.7.2 and .NET Core 2.0
15-
- Downgraded Newtonsoft JSON version requirement to be 11.0.1 and higher for .NET Core and .NET Standard and 8.0.1 for .NET Framework to allow for a bit greater compatibility
16-
</PackageReleaseNotes>
14+
<PackageReleaseNotes>- Fixed a bug when uploading files larger than 5 MB throwing an exception stating that the oneDriveUploadSession is NULL</PackageReleaseNotes>
1715
<PackageLicenseUrl>https://github.com/KoenZomers/OneDriveAPI/blob/master/LICENSE.md</PackageLicenseUrl>
1816
<Copyright>Koen Zomers</Copyright>
1917
<RootNamespace>KoenZomers.OneDrive.Api</RootNamespace>

Api/KoenZomers.OneDrive.Api.xml

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Api/OneDriveGraphApi.cs

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ https://www.nuget.org/packages/KoenZomers.OneDrive.Api
6767

6868
## Version History
6969

70+
2.3.0.2 - May 16, 2019
71+
72+
- Fixed a bug when uploading files larger than 5 MB throwing an exception stating that the oneDriveUploadSession is NULL
73+
7074
2.3.0.1 - May 5, 2019
7175

7276
- Recompiled to support multi platform to support .NET Standard 2.0, .NET Framework 4.5.2, .NET Framework 4.7.2 and .NET Core 2.0

0 commit comments

Comments
 (0)