Uploading Files
As of 1.11.0, Wolverine supports file uploads through the standard ASP.Net Core IFormFile or IFormFileCollection types. All you need to do is to have an input parameter to your Wolverine.HTTP endpoint of these types like so:
public class FileUploadEndpoint
{
// If you have exactly one file upload, take
// in IFormFile
[WolverinePost("/upload/file")]
public static Task Upload(IFormFile file)
{
// access the file data
return Task.CompletedTask;
}
// If you have multiple files at one time,
// use IFormCollection
[WolverinePost("/upload/files")]
public static Task Upload(IFormFileCollection files)
{
// access files
return Task.CompletedTask;
}
}See Upload files in ASP.NET Core for more information about these types.
Multipart Uploads 5.16
Wolverine also supports multipart uploads where you need to combine file uploads with form metadata. You can:
- Use multiple named
IFormFileparameters, each bound by form field name - Combine a
[FromForm]complex type with a separateIFormFileparameter - Use
IFormCollectionfor raw access to all form fields and files
public static class MultipartUploadEndpoints
{
// Multiple named file parameters are bound by form field name
[WolverinePost("/upload/named-files")]
public static string UploadNamedFiles(IFormFile document, IFormFile thumbnail)
{
return $"{document?.FileName}|{document?.Length}|{thumbnail?.FileName}|{thumbnail?.Length}";
}
// Combine [FromForm] metadata with a file upload in a single endpoint
[WolverinePost("/upload/mixed")]
public static string UploadMixed([FromForm] UploadMetadata metadata, IFormFile file)
{
return $"{metadata.Title}|{metadata.Description}|{file?.FileName}|{file?.Length}";
}
// Use IFormCollection for raw access to all form data and files
[WolverinePost("/upload/form-collection")]
public static string UploadFormCollection(IFormCollection form)
{
var keys = string.Join(",", form.Keys.OrderBy(k => k));
var fileCount = form.Files.Count;
return $"keys:{keys}|files:{fileCount}";
}
}Each IFormFile parameter is matched to the uploaded file by its parameter name. When sending a multipart request, make sure the form field names match the parameter names in your endpoint method.

