ColinChang.BigFileForm
1.0.2
See the version list below for details.
dotnet add package ColinChang.BigFileForm --version 1.0.2
NuGet\Install-Package ColinChang.BigFileForm -Version 1.0.2
<PackageReference Include="ColinChang.BigFileForm" Version="1.0.2" />
paket add ColinChang.BigFileForm --version 1.0.2
#r "nuget: ColinChang.BigFileForm, 1.0.2"
// Install ColinChang.BigFileForm as a Cake Addin #addin nuget:?package=ColinChang.BigFileForm&version=1.0.2 // Install ColinChang.BigFileForm as a Cake Tool #tool nuget:?package=ColinChang.BigFileForm&version=1.0.2
What this is about?
an Asp.Net Core middleware that can process multiple form parameters including big files and texts in a POST/PUT
method by overriding object HttpConext.Request.Form
and HttpConext.Request.Form.Files
.
How to use it?
this middleware is easy to be used by a few steps.
configuration
configures the file size limitation in appsettings.json
.
{
"BigFileFormOptions": {
"MinBodySize": 5242880,
"MaxBodySize": 209715200
}
}
config the options in Startup.ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<BigFileFormOptions>(Configuration.GetSection(nameof(BigFileFormOptions)));
services.AddControllers();
}
use the middleware
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
//use big file form middleware
app.UseBigFileForm();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
try it
after using this middleware, you could get your big file and text parameters by Request.Form.Files
and Request.Forms
when you try to upload a big file between MinBodySize
and MaxBodySize
. It can only work in a POST or PUT method.
[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{
private ILogger _logger;
public TestController(ILogger<TestController> logger) => _logger = logger;
[HttpPost]
[DisableFormValueModelBinding]
[DisableRequestSizeLimit]
public async Task PostAsync()
{
var releaseNotes = Request.Form["releasenotes"];
_logger.LogInformation(releaseNotes);
var app = Request.Form.Files["app"];
await using var fileStream = System.IO.File.Create(app.FileName);
await app.CopyToAsync(fileStream);
}
}
file size limitation
when we try to upload a big file, we have to know both the Kestrel server and default form have its limitation. We could adjust them by configuring KestrelServerOptions
and FormOptions
.
{
"KestrelServerOptions": {
"Limits": {
"KeepAliveTimeout": 300,
"RequestHeadersTimeout": 300,
"MaxRequestBodySize": 209715200,
"Http2": {
"MaxStreamsPerConnection": 104857600,
"MaxFrameSize": 16777215
}
}
},
"BigFileFormOptions": {
"MinBodySize": 5242880,
"MaxBodySize": 209715200
}
}
public void ConfigureServices(IServiceCollection services)
{
services
// modify kestrel limitation
.Configure<KestrelServerOptions>(Configuration.GetSection(nameof(KestrelServerOptions)))
// modify default form limitation
.Configure<FormOptions>(options =>
{
var maxRequestBodySize =
int.Parse(Configuration["KestrelServerOptions:Limits:MaxRequestBodySize"]);
options.ValueLengthLimit = maxRequestBodySize;
options.MultipartBodyLengthLimit = maxRequestBodySize;
})
// big file form
.Configure<BigFileFormOptions>(Configuration.GetSection(nameof(BigFileFormOptions)));
services.AddControllers();
}
Sample
Sample project shows how to use this middleware.
Product | Versions 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- BouncyCastle.NetCore (>= 1.8.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.