MinimalHelpers.Binding 1.0.19

Additional Details

Support for IForm and IFormFile binding in Minimal APIs has been added in NET 7.0.

dotnet add package MinimalHelpers.Binding --version 1.0.19
NuGet\Install-Package MinimalHelpers.Binding -Version 1.0.19
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="MinimalHelpers.Binding" Version="1.0.19" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MinimalHelpers.Binding --version 1.0.19
#r "nuget: MinimalHelpers.Binding, 1.0.19"
#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.
// Install MinimalHelpers.Binding as a Cake Addin
#addin nuget:?package=MinimalHelpers.Binding&version=1.0.19

// Install MinimalHelpers.Binding as a Cake Tool
#tool nuget:?package=MinimalHelpers.Binding&version=1.0.19

Minimal APIs Binding Helpers

GitHub Super-Linter Nuget Nuget

A library that provides Binding helpers for Minimal API projects.

Installation

The library is available on NuGet. Just search MinimalHelpers.Binding in the Package Manager GUI or run the following command in the Package Manager Console:

Install-Package MinimalHelpers.Binding

Usage

IFormFile and IFormFileCollection binding

Use a FormFileContent or FormFileContentCollection argument in the route handler that must receive a single file or a collection of files, then call the corresponding Accepts* extension method on the endpoint definition:

app.MapPost("/api/single-file", (FormFileContent file) =>
{
    return Results.Ok(new
    {
        file.Content.FileName,
        file.Content.ContentType,
        file.Content.Length
    });
})
.AcceptsFormFile();

app.MapPost("/api/multiple-files", (FormFileContentCollection files) =>
{
    return Results.Ok(files.Content.Select(file => new
    {
        file.FileName,
        file.ContentType,
        file.Length
    }));
})
.AcceptsFormFileCollection();

Add the FormFile Operation Filter to Swagger, so that it will be able to correctly handle file input:

builder.Services.AddSwaggerGen(options =>
{
    options.AddFormFile();
});

Contribute

The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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
1.0.19 457 7/25/2022
1.0.17 374 5/16/2022
1.0.12 385 3/4/2022
1.0.6 395 2/18/2022