Skip to content

Map-From-Multipart binding

Support a variety of map-from-multipart bindings:

  1. File - MapFromMultipartFileAttribute
  2. Json - MapFromMultipartJsonAttribute

Simply decorate your request dto property (must be read and write) with the corresponding 'MapFromMultipartAttribute'.

You also need to specify the multipart section position (zero based).

File

public record CommandDto
{
    [MapFromMultipartFile(0)] 
    public IFormFile File { get; set; }

    [MapFromMultipartJson(1)] 
    public PayloadDto Payload { get; set; }
}

Json

public record CommandDto
{
    [MapFromMultipartFile(0)] 
    public IFormFile File { get; set; }

    [MapFromMultipartJson(1)] 
    public PayloadDto Payload { get; set; }
}