Skip to content

[Question]: FormData parameters with file uploads #3682

@RickyNHSPS

Description

@RickyNHSPS

What are you wanting to achieve?

I am trying to get the generated openapi json to generate my parameters decorated as [FromForm] correctly. Currently, it generates as a single object parameter as opposed to multiple parameters that can be provided.

using version 8.1.4 or greater, I get the following

Image.

As opposed to the below using an older version (eg. v6.6.2)

Image Image

There was this discussion before that identified that using WithOpenApi would make it behave as I desire it to, but it doesn't work anymore, it appears that the WithOpenApi behaviour has been changed just to make it consistent. dotnet/aspnetcore#52284

Is there any way to get the previous behavior, so that I can accommodate request data and files in a single fromform described parameter.

What code or approach do you have so far?

group.MapPost("/send-email", async (
[FromServices] ISender sender, HttpContext ctx, [FromForm] PublishSendEmailRequest request) =>
{
var response = await sender.Send(request);
return Results.Ok(response);
})
.WithName("SendEmail")
.WithDescription("Sends an email")
.Accepts("multipart/form-data")
.WithOpenApi();

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionstaleStale issues or pull requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions