Skip to content
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

.NET 7: Add sample for Minimal API Bind the request body as a Stream or PipeReader #26346

Closed
Tracked by #26326
Rick-Anderson opened this issue Jul 7, 2022 · 1 comment · Fixed by #26437
Closed
Tracked by #26326
Labels
code help wanted Sample code help wanted.

Comments

@Rick-Anderson
Copy link
Contributor

Rick-Anderson commented Jul 7, 2022

See https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-net-7-preview-1/

Sample goes in
https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/bindStreamPipeReader/7.0-samples

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.MapPost("/fileUp", async (IFormFile file) =>
{
    string tempfile = Path.GetTempFileName();
    using var stream = File.OpenWrite(tempfile);
    await file.CopyToAsync(stream);
});

app.MapPost("/FilesUp", async (IFormFileCollection myFiles) =>
{
    foreach (var file in myFiles)
    {
        string tempfile = Path.GetTempFileName();
        using var stream = File.OpenWrite(tempfile);
        await file.CopyToAsync(stream);
    }
});

app.Run();
@sammychinedu2ky
Copy link
Contributor

I'll take this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code help wanted Sample code help wanted.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants