Swashbuckle.AspNetCore.JsonMultipartFormDataSupport 1.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Swashbuckle.AspNetCore.JsonMultipartFormDataSupport --version 1.4.0
                    
NuGet\Install-Package Swashbuckle.AspNetCore.JsonMultipartFormDataSupport -Version 1.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Swashbuckle.AspNetCore.JsonMultipartFormDataSupport" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Swashbuckle.AspNetCore.JsonMultipartFormDataSupport" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Swashbuckle.AspNetCore.JsonMultipartFormDataSupport" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Swashbuckle.AspNetCore.JsonMultipartFormDataSupport --version 1.4.0
                    
#r "nuget: Swashbuckle.AspNetCore.JsonMultipartFormDataSupport, 1.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Swashbuckle.AspNetCore.JsonMultipartFormDataSupport@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Swashbuckle.AspNetCore.JsonMultipartFormDataSupport&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Swashbuckle.AspNetCore.JsonMultipartFormDataSupport&version=1.4.0
                    
Install as a Cake Tool

https://www.nuget.org/packages/Swashbuckle.AspNetCore.JsonMultipartFormDataSupport

Swashbuckle.AspNetCore.JsonMultipartFormDataSupport

Adds support for json in multipart/form-data requests.

Exmaple

Usage

  1. Simple add this to your ConfigureServices
services.AddJsonMultipartFormDataSupport();

Or manually:

  • Binder
services
    .AddMvc(
        properties => {
            // ...
            properties.ModelBinderProviders.Insert(0, new FormDataJsonBinderProvider()); // Here
        }
    )
  • Operation filter
services.AddSwaggerGen(c => {
        c.OperationFilter<MultiPartJsonOperationFilter>();
    });
  1. Add to your Controller
[HttpPost]
[Consumes("multipart/form-data")] 
public async Task<IActionResult> Post([FromForm] MultipartFormData<Product> multiPartData) {
    var file = multiPartData.File;
    var product = multiPartData.Json;
}

or

[HttpPost]
[Consumes("multipart/form-data")] 
public async Task<IActionResult> Post([FromForm] MultipartRequiredFormData<Product> multiPartData) {
    var file = multiPartData.File;
    var product = multiPartData.Json;
}

Or you can create your on wrapper

public class MyWrapper {
    [FromJson] // <-- This attribute is required for binding.
    public MyModel Json { get; set; }

    public IFormFile File { get; set; }
}

and then

[HttpPost]
[Consumes("multipart/form-data")] 
public async Task<IActionResult> Post([FromForm] MyWrapper myWrapper) {
    // code
}

Notes:

It automatically adds examples from class which implements IExampleProvider<MyModel>.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 26,841 11/17/2024
1.10.1 14,062 11/15/2024
1.10.0 3,195 10/22/2024
1.9.0 98,089 12/17/2023
1.8.0 110,356 1/25/2023
1.7.1 23,321 7/24/2022
1.7.0 28,718 4/14/2022
1.6.1 10,978 11/2/2021
1.6.0 463 10/31/2021
1.5.0 4,359 6/28/2021
1.4.2 45,528 9/22/2020
1.4.1 54,846 6/20/2020
1.4.0 4,092 4/6/2020
1.3.0 2,080 1/13/2020
1.2.3 693 1/10/2020
1.2.2 723 1/9/2020
1.2.1 725 1/9/2020
1.2.0 704 1/9/2020
1.1.2 714 11/25/2019
1.1.1 672 11/6/2019
1.1.0 718 10/29/2019
1.0.1 714 9/25/2019
1.0.0 939 9/25/2019

- Now you can choose your serializer.