microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Allow writing to request stream for uploading content

Open
#1,686 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Request: enhancement
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

Is your feature request related to a problem? Please describe.
Developers should be able to write to the request stream for uploads so they can generate content 'on the fly' without needing to buffer it in memory.

Describe the solution you'd like

An overload for ContentRequestBuilder.PutAsync which accepts a Stream -> () delegate . That is:

public async Task PutAsync(Action<Stream> write, Action<ContentRequestBuilderPutRequestConfiguration>? requestConfiguration = default) { }

Describe alternatives you've considered

Buffering content in-memory by using a MemoryStream and using the existing overload which accepts a Stream.

Additional context

There is an overload for PutAsync which accepts an existing stream which is useful for pull-based streaming where the content already exists. For example, from a file.

https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/7a2be45d2cf37f18a32cc9a60d0edf441fd23a08/src/Microsoft.Graph/Generated/Drives/Item/Items/Item/Content/ContentRequestBuilder.cs#L67-L79

The overload I'm proposing would be better for push-based streaming where you're generating content because it doesn't require you to hold it in-memory. For example:

  1. constructing a zip archive from many files[^1]
  2. serializing an object graph[^2]

I understand this SDK is generated. I'm guessing this kind of overload will either need to be supported by Kiota or added as an extension manually (if Kiota's interfaces actually allow access to the request stream.)

[^1]: Streaming Zip on ASP.NET Core
https://blog.stephencleary.com/2016/11/streaming-zip-on-aspnet-core.html
An article which demonstrates the push-pull distinction with zip archives and ASP.NET Core.
[^2]: Uploading data with HttpClient using a "push" model
https://thomaslevesque.com/2013/11/30/uploading-data-with-httpclient-using-a-push-model/
An article which demonstrates the push-pull distinction with serialization ASP.NET.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated ContentRequestBuilder.PutAsync overloads in src/Microsoft.Graph/Generated/Drives/Item/Items/Item/Content/ContentRequestBuilder.cs. Inspect the Kiota interfaces and request-stream support to determine whether a write delegate can be exposed without buffering. Done means push-based content generation can upload through PutAsync while preserving the existing stream overload and request configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.