-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-model-binding
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
The #38153 introduced the support for binding Stream/PipeReader, since it is common pattern a similar support must be available in Controller Actions.
Describe the solution you'd like
I would like to replicate the same code I have for a Minimal APIs:
app.MapPost("v1/feeds", async (QueueClient queueClient, Stream body, CancellationToken cancellationToken) =>
{
await queueClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
await queueClient.SendMessageAsync(await BinaryData.FromStreamAsync(body), cancellationToken: cancellationToken);
});I my Controller Actions:
[Route("v1/feeds")]
[ApiController]
public class FeedsController : ControllerBase
{
[HttpPost]
public async Task<ActionResult> Post(QueueClient queueClient, Stream body, CancellationToken cancellationToken)
{
await queueClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
await queueClient.SendMessageAsync(await BinaryData.FromStreamAsync(body), cancellationToken: cancellationToken);
return Created("[somelocation]", null);
}
}I should also be able to explicitly define the parameter [FromBody] Stream body and must have the same behavior.
Additional context
The same considerations applied to Minimal should be applied here as well:
- When ingesting data, the
Streamwill be the same object asHttpRequest.Body. - The request body isn’t buffered by default. After the body is read, it’s not rewindable (you can’t read the stream multiple times).
- The
Stream/PipeReaderare not usable outside of the controller action handler as the underlying buffers will be disposed and/or reused.
gurustron, flibustier7seas, frankbuckley, stamminator, beryozavv and 6 morecommonsensesoftware and pri-kise
Metadata
Metadata
Assignees
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-model-binding