A small library for creating multipart/form-data content from flat objects.
Create an instance of the MultipartFormDataFactory class or use MultipartFormDataFactory.Default
static field, then pass it a request object:
var multipartFormDataFactory = new MultipartFormDataFactory();
var content = await multipartFormDataFactory.Create(request, token);
This will return a System.Net.Http.MultipartFormDataContent instance. Later is can be used in http client instance like this:
var response = await _httpClient.PostAsync(url, content, token);
IFormFile
abstraction should be used for files.
dotnet run -c RELEASE --project HttpMultipartFormDataFactory.Tests
Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated |
---|---|---|---|---|---|---|
CreateWithCache | 639.1 us | 5.75 us | 5.38 us | 227.5391 | 113.2813 | 569 KB |
CreateWithoutCache | 876.3 us | 16.77 us | 17.23 us | 275.3906 | 137.6953 | 631 KB |