HttpMultipartParser 8.4.0
dotnet add package HttpMultipartParser --version 8.4.0
NuGet\Install-Package HttpMultipartParser -Version 8.4.0
<PackageReference Include="HttpMultipartParser" Version="8.4.0" />
paket add HttpMultipartParser --version 8.4.0
#r "nuget: HttpMultipartParser, 8.4.0"
// Install HttpMultipartParser as a Cake Addin #addin nuget:?package=HttpMultipartParser&version=8.4.0 // Install HttpMultipartParser as a Cake Tool #tool nuget:?package=HttpMultipartParser&version=8.4.0
Http Multipart Parser
Release Notes | NuGet (stable) | MyGet (prerelease) |
---|---|---|
About
The Http Multipart Parser does it exactly what it claims on the tin: parses multipart/form-data. This particular parser is well suited to parsing large data from streams as it doesn't attempt to read the entire stream at once and procudes a set of streams for file data.
Installation
The easiest way to include HttpMultipartParser in your project is by adding the nuget package to your project:
PM> Install-Package HttpMultipartParser
.NET framework suport
- The parser was built for and tested on .NET 4.8, .NET standard 2.1, .NET 5.0 and .NET 6.0.
- Version 5.1.0 was the last version that supported .NET 4.6.1, NET 4.7.2 and .NET standard 2.0.
- Version 2.2.4 was the last version that supported older .NET platforms such as .NET 4.5 and .NET standard 1.3.
Usage
Non-Streaming (Simple, don't use on very large files)
- Parse the stream containing the multipart/form-data by invoking
MultipartFormDataParser.Parse
(or it's asynchronous counterpartMultipartFormDataParser.ParseAsync
). - Access the data through the parser.
Streaming (Handles large files)
- Create a new StreamingMultipartFormDataParser with the stream containing the multipart/form-data
- Set up the ParameterHandler and FileHandler delegates
- Call
parser.Run()
(or it's asynchronous counterpartparser.RunAsync()
) - The delegates will be called as data streams in.
Examples
Single file
// stream:
-----------------------------41952539122868
Content-Disposition: form-data; name="username"
example
-----------------------------41952539122868
Content-Disposition: form-data; name="email"
example@data.com
-----------------------------41952539122868
Content-Disposition: form-data; name="files[]"; filename="photo1.jpg"
Content-Type: image/jpeg
ExampleBinaryData012031203
-----------------------------41952539122868--
// ===== Simple Parsing ====
// You can parse synchronously:
var parser = MultipartFormDataParser.Parse(stream);
// Or you can parse asynchronously:
var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false);
// From this point the data is parsed, we can retrieve the
// form data using the GetParameterValue method.
var username = parser.GetParameterValue("username");
var email = parser.GetParameterValue("email");
// Files are stored in a list:
var file = parser.Files.First();
string filename = file.FileName;
Stream data = file.Data;
// ==== Advanced Parsing ====
var parser = new StreamingMultipartFormDataParser(stream);
parser.ParameterHandler += parameter => DoSomethingWithParameter(parameter);
parser.FileHandler += (name, fileName, type, disposition, buffer, bytes, partNumber, additionalProperties) =>
{
// Write the part of the file we've received to a file stream. (Or do something else)
filestream.Write(buffer, 0, bytes);
}
// You can parse synchronously:
parser.Run();
// Or you can parse asynchronously:
await parser.RunAsync().ConfigureAwait(false);
Multiple Parameters
// stream:
-----------------------------41952539122868
Content-Disposition: form-data; name="checkbox"
likes_cake
-----------------------------41952539122868
Content-Disposition: form-data; name="checkbox"
likes_cookies
-----------------------------41952539122868--
// ===== Simple Parsing ====
// You can parse synchronously:
var parser = MultipartFormDataParser.Parse(stream);
// Or you can parse asynchronously:
var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false);
// From this point the data is parsed, we can retrieve the
// form data from the GetParameterValues method
var checkboxResponses = parser.GetParameterValues("checkbox");
foreach(var parameter in checkboxResponses)
{
Console.WriteLine("Parameter {0} is {1}", parameter.Name, parameter.Data)
}
Multiple Files
// stream:
-----------------------------41111539122868
Content-Disposition: form-data; name="files[]"; filename="photo1.jpg"
Content-Type: image/jpeg
MoreBinaryData
-----------------------------41111539122868
Content-Disposition: form-data; name="files[]"; filename="photo2.jpg"
Content-Type: image/jpeg
ImagineLotsOfBinaryData
-----------------------------41111539122868--
// ===== Simple Parsing ====
// You can parse synchronously:
var parser = MultipartFormDataParser.Parse(stream);
// Or you can parse asynchronously:
var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false);
// Loop through all the files
foreach(var file in parser.Files)
{
Stream data = file.Data;
// Do stuff with the data.
}
// ==== Advanced Parsing ====
var parser = new StreamingMultipartFormDataParser(stream);
parser.ParameterHandler += parameter => DoSomethingWithParameter(parameter);
parser.FileHandler += (name, fileName, type, disposition, buffer, bytes, partNumber, additionalProperties) =>
{
// Write the part of the file we've received to a file stream. (Or do something else)
// Assume that filesreamsByName is a Dictionary<string, FileStream> of all the files
// we are writing.
filestreamsByName[name].Write(buffer, 0, bytes);
};
parser.StreamClosedHandler += ()
{
// Do things when my input stream is closed
};
// You can parse synchronously:
parser.Run();
// Or you can parse asynchronously:
await parser.RunAsync().ConfigureAwait(false);
Licensing
This project is licensed under MIT.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.0)
- System.Buffers (>= 4.5.1)
-
.NETStandard 2.1
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.0)
- System.Buffers (>= 4.5.1)
-
net6.0
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.0)
- System.Buffers (>= 4.5.1)
-
net7.0
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.0)
- System.Buffers (>= 4.5.1)
NuGet packages (35)
Showing the top 5 NuGet packages that depend on HttpMultipartParser:
Package | Downloads |
---|---|
StrongGrid
StrongGrid is a strongly typed .NET client for SendGrid's v3 API. |
|
ZoomNet
ZoomNet is a strongly typed .NET client for Zoom's API. |
|
Pangea.SDK
.NET SDK to access Pangea API services on pangea.cloud |
|
IctBaden.Stonehenge3
X-Platform Web Application Framework |
|
Butterfly.Web
Simple RESTlike and Subscription API server in C# |
GitHub repositories (10)
Showing the top 5 popular GitHub repositories that depend on HttpMultipartParser:
Repository | Stars |
---|---|
restsharp/RestSharp
Simple REST and HTTP API Client for .NET
|
|
sendgrid/sendgrid-csharp
The Official Twilio SendGrid C#, .NetStandard, .NetCore API Library
|
|
uholeschak/ediabaslib
.NET BMW and VAG Ediabas interpreter library
|
|
bassmaster187/TeslaLogger
TeslaLogger is a self hosted data logger for your Tesla Model S/3/X/Y. Actually it supports RaspberryPi 3B, 3B+, 4B, Docker and Synology NAS.
|
|
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
|
Version | Downloads | Last updated |
---|---|---|
8.4.0 | 587,875 | 4/8/2024 |
8.3.0 | 380,903 | 1/10/2024 |
8.2.0 | 459,607 | 6/22/2023 |
8.1.0 | 454,519 | 2/5/2023 |
8.0.0 | 246,144 | 1/8/2023 |
7.1.0 | 302,816 | 10/30/2022 |
7.0.0 | 275,360 | 7/7/2022 |
6.0.1 | 70,464 | 5/31/2022 |
5.1.0 | 641,018 | 3/5/2022 |
5.0.1 | 2,666,147 | 7/11/2021 |
5.0.0 | 1,670,324 | 1/3/2021 |
4.4.0 | 80,501 | 12/4/2020 |
4.3.1 | 593,636 | 5/1/2020 |
4.3.0 | 1,690 | 5/1/2020 |
4.2.0 | 66,453 | 3/30/2020 |
4.1.0 | 3,330 | 3/22/2020 |
4.0.0 | 110,621 | 3/11/2020 |
3.1.0 | 201,501 | 12/15/2019 |
3.0.0 | 135,703 | 11/25/2019 |
2.2.4 | 1,284,815 | 6/16/2017 |
2.2.3 | 57,983 | 1/11/2017 |
2.2.2 | 2,472 | 1/10/2017 |
2.2.1 | 338,557 | 12/7/2016 |
2.2.0 | 56,989 | 12/5/2016 |
2.1.7 | 28,044 | 10/30/2016 |
2.1.6 | 31,108 | 9/23/2016 |
2.1.5 | 2,482 | 9/23/2016 |
2.1.4 | 43,522 | 4/18/2016 |
2.1.3 | 6,386 | 2/13/2016 |
2.1.2 | 2,502 | 2/13/2016 |
2.1.1 | 8,080 | 1/3/2016 |
2.0.1 | 8,486 | 10/18/2015 |
2.0.0 | 8,354 | 8/23/2015 |
1.1.5 | 5,333 | 7/7/2015 |
1.1.4 | 20,262 | 2/13/2015 |
1.1.3 | 6,805 | 2/13/2015 |
1.1.2 | 2,570 | 2/6/2015 |
1.1.0 | 2,499 | 2/6/2015 |
1.0.3 | 2,482 | 2/6/2015 |
1.0.2 | 5,032 | 11/25/2014 |