jericho - HttpMultipartParser 7.1.0-beta0011
A C# Http Multipart/form-data parser that works correctly on binary data and very large files.
PM> Install-Package HttpMultipartParser -Version 7.1.0-beta0011 -Source https://www.myget.org/F/jericho/api/v3/index.json
> nuget.exe install HttpMultipartParser -Version 7.1.0-beta0011 -Source https://www.myget.org/F/jericho/api/v3/index.json
> dotnet add package HttpMultipartParser --version 7.1.0-beta0011 --source https://www.myget.org/F/jericho/api/v3/index.json
source https://www.myget.org/F/jericho/api/v3/index.json
nuget HttpMultipartParser ~> 7.1.0-beta0011
Copy to clipboard
> choco install HttpMultipartParser --version 7.1.0-beta0011 --source https://www.myget.org/F/jericho/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "jericho" -SourceLocation "https://www.myget.org/F/jericho/api/v2"
Install-Module -Name "HttpMultipartParser" -RequiredVersion "7.1.0-beta0011" -Repository "jericho" -AllowPreRelease
Copy to clipboard
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 currently supports .NET framework 4.8 and any framework supporting
.NET Standard 2.1(which includes .NET 5.0 and all subsequent versions as well as some legacy versions such as .NET Core 3.x and ASP.NET Core 3.x). - 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.
-
.NETFramework 4.8
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.0)
- System.Buffers (>= 4.5.1)
-
.NETFramework 5.0
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.0)
- System.Buffers (>= 4.5.1)
-
.NETFramework 6.0
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.0)
- System.Buffers (>= 4.5.1)
-
.NETStandard 2.1
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.0)
- System.Buffers (>= 4.5.1)
- .NETFramework 4.8: 4.8.0.0
- .NETFramework 5.0: 5.0.0.0
- .NETFramework 6.0: 6.0.0.0
- .NETStandard 2.1: 2.1.0.0
OwnersJericho |
AuthorsJake Woods, Jeremie Desautels |
Project URLhttps://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser |
LicenseUnknown |
Tagshttp multipart parser form data |
Info1597 total downloads |
| 58 downloads for version 7.1.0-beta0011 |
| Download (107.32 KB) |
| Found on the current feed only |
Package history
| Version | Size | Last updated | Downloads | Mirrored? | |||
|---|---|---|---|---|---|---|---|
|
|
8.3.0-beta0013 | 121.85 KB | Thu, 22 Jun 2023 14:23:44 GMT | 64 |
|
||
|
|
8.2.0 | 121.74 KB | Thu, 22 Jun 2023 14:33:51 GMT | 55 |
|
||
|
|
8.2.0-beta0015 | 121.84 KB | Thu, 22 Jun 2023 14:05:24 GMT | 47 |
|
||
|
|
8.2.0-beta0011 | 121.31 KB | Wed, 21 Jun 2023 20:07:34 GMT | 56 |
|
||
|
|
8.2.0-beta0005 | 121.45 KB | Sun, 05 Feb 2023 20:51:55 GMT | 52 |
|
||
|
|
8.1.0 | 121.37 KB | Sun, 05 Feb 2023 21:20:32 GMT | 43 |
|
||
|
|
8.1.0-beta0014 | 121.46 KB | Sat, 04 Feb 2023 19:36:27 GMT | 48 |
|
||
|
|
8.1.0-beta0013 | 121.3 KB | Sun, 08 Jan 2023 14:49:21 GMT | 55 |
|
||
|
|
8.0.0 | 121.2 KB | Sun, 08 Jan 2023 15:04:07 GMT | 59 |
|
||
|
|
7.2.0-beta0016 | 121.32 KB | Sat, 07 Jan 2023 18:54:32 GMT | 51 |
|
||
|
|
7.2.0-beta0014 | 121.35 KB | Sat, 07 Jan 2023 18:49:02 GMT | 55 |
|
||
|
|
7.2.0-beta0008 | 107.33 KB | Fri, 09 Dec 2022 17:57:56 GMT | 49 |
|
||
|
|
7.2.0-beta0006 | 107.31 KB | Sun, 30 Oct 2022 16:20:25 GMT | 44 |
|
||
|
|
7.1.0 | 107.22 KB | Sun, 30 Oct 2022 16:28:08 GMT | 56 |
|
||
|
|
7.1.0-beta0011 | 107.32 KB | Sun, 30 Oct 2022 16:10:42 GMT | 58 |
|
||
|
|
7.1.0-beta0008 | 107.33 KB | Thu, 07 Jul 2022 14:43:34 GMT | 50 |
|
||
|
|
7.0.0 | 107.25 KB | Thu, 07 Jul 2022 14:52:53 GMT | 54 |
|
||
|
|
6.1.0-ignore-invalid-p0025 | 107.49 KB | Sat, 02 Jul 2022 15:33:46 GMT | 65 |
|
||
|
|
6.1.0-beta0022 | 102.93 KB | Tue, 31 May 2022 17:15:42 GMT | 53 |
|
||
|
|
6.1.0-beta0020 | 102.95 KB | Tue, 31 May 2022 17:07:14 GMT | 52 |
|
||
|
|
5.2.0-beta0025 | 102.92 KB | Mon, 30 May 2022 14:04:45 GMT | 49 |
|
||
|
|
5.2.0-beta0023 | 102.46 KB | Sat, 05 Mar 2022 17:07:30 GMT | 47 |
|
||
|
|
5.2.0-beta0020 | 100.39 KB | Sat, 05 Mar 2022 16:55:40 GMT | 58 |
|
||
|
|
5.2.0-beta0019 | 100.42 KB | Sat, 05 Mar 2022 16:21:02 GMT | 54 |
|
||
|
|
5.1.0-beta0052 | 100.41 KB | Sat, 05 Mar 2022 16:05:53 GMT | 57 |
|
||
|
|
5.1.0-beta0049 | 100.41 KB | Sat, 05 Mar 2022 15:07:31 GMT | 60 |
|
||
|
|
5.1.0-alpha0048 | 100.31 KB | Sat, 05 Mar 2022 15:01:01 GMT | 49 |
|
||
|
|
5.1.0-alpha0044 | 99.63 KB | Sat, 25 Sep 2021 14:57:50 GMT | 53 |
|
||
|
|
5.1.0-alpha0043 | 99.72 KB | Wed, 14 Jul 2021 17:40:10 GMT | 50 |
|
||
|
|
5.1.0-alpha0041 | 98.67 KB | Wed, 14 Jul 2021 16:03:15 GMT | 54 |
|