-
Notifications
You must be signed in to change notification settings - Fork 56
Add support for Complete file upload api endpoint #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KoditkarVedant
merged 3 commits into
main
from
479-add-support-for-complete-file-upload-endpoint
Oct 18, 2025
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Notion.Client | ||
| { | ||
| public sealed partial class FileUploadsClient | ||
| { | ||
| public async Task<CompleteFileUploadResponse> CompleteAsync( | ||
| CompleteFileUploadRequest completeFileUploadRequest, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| if (completeFileUploadRequest == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(completeFileUploadRequest)); | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(completeFileUploadRequest.FileUploadId)) | ||
| { | ||
| throw new ArgumentException("FileUploadId cannot be null or empty.", nameof(completeFileUploadRequest.FileUploadId)); | ||
| } | ||
|
|
||
| var path = ApiEndpoints.FileUploadsApiUrls.Complete(completeFileUploadRequest.FileUploadId); | ||
|
|
||
| return await _restClient.PostAsync<CompleteFileUploadResponse>( | ||
| path, | ||
| body: null, | ||
| cancellationToken: cancellationToken | ||
| ); | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
Src/Notion.Client/Api/FileUploads/Complete/Request/CompleteFileUploadRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Notion.Client | ||
| { | ||
| public class CompleteFileUploadRequest : ICompleteFileUploadPathParameters | ||
| { | ||
| public string FileUploadId { get; set; } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
Src/Notion.Client/Api/FileUploads/Complete/Request/ICompleteFileUploadPathParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Notion.Client | ||
| { | ||
| public interface ICompleteFileUploadPathParameters | ||
| { | ||
| public string FileUploadId { get; set; } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
Src/Notion.Client/Api/FileUploads/Complete/Response/CompleteFileUploadResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Notion.Client | ||
| { | ||
| public class CompleteFileUploadResponse : FileObjectResponse | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
|
|
||
| namespace Notion.IntegrationTests | ||
| { | ||
| public static class StreamSplitExtensions | ||
| { | ||
| public static IEnumerable<Stream> Split(Stream inputStream, int numberOfParts) | ||
| { | ||
| if (numberOfParts <= 0) | ||
| { | ||
| throw new ArgumentException("Number of parts must be greater than zero.", nameof(numberOfParts)); | ||
| } | ||
|
|
||
| if (inputStream == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(inputStream)); | ||
| } | ||
|
|
||
| MemoryStream buffer = new(); | ||
| inputStream.CopyTo(buffer); | ||
|
|
||
| buffer.Position = 0; | ||
|
|
||
| long totalSize = buffer.Length; | ||
| long baseSize = totalSize / numberOfParts; | ||
| long remainder = totalSize % numberOfParts; | ||
|
|
||
| while (numberOfParts-- > 0) | ||
| { | ||
| long currentPartSize = numberOfParts == 0 ? baseSize + remainder : baseSize; | ||
KoditkarVedant marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var partStream = new MemoryStream(); | ||
| CopyStream(buffer, partStream, currentPartSize); | ||
| partStream.Position = 0; | ||
| yield return partStream; | ||
| } | ||
| } | ||
|
|
||
| private static void CopyStream(Stream buffer, MemoryStream partStream, long bytesToCopy) | ||
| { | ||
| byte[] tempBuffer = new byte[81920]; // 80 KB buffer | ||
|
|
||
| while (bytesToCopy > 0) | ||
| { | ||
| int bytesToRead = (int)Math.Min(tempBuffer.Length, bytesToCopy); | ||
| int bytesRead = buffer.Read(tempBuffer, 0, bytesToRead); | ||
| if (bytesRead == 0) | ||
| { | ||
| break; // End of stream | ||
| } | ||
|
|
||
| partStream.Write(tempBuffer, 0, bytesRead); | ||
| bytesToCopy -= bytesRead; | ||
| } | ||
| } | ||
|
|
||
| // enumerate with index | ||
| public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> source) | ||
| { | ||
| if (source == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(source)); | ||
| } | ||
|
|
||
| int index = 0; | ||
| foreach (var item in source) | ||
| { | ||
| yield return (item, index++); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.