RequestPart class

Binds a multipart/form-data request part to a method parameter.

Used for handling file uploads and complex form data in multipart/form-data requests. Each part can contain binary data, form fields, or mixed content.

Parameters

  • value: Name of the request part to bind (defaults to parameter name)
  • required: Whether the part is mandatory (default: true)
  • contentType: Expected content type for validation
  • maxSize: Maximum allowed size in bytes

Example

@RestController()
class UploadController {
  @PostMapping('/upload')
  UploadResult uploadFile(
    @RequestPart('document') Uint8List fileData,
    @RequestPart('metadata', contentType: 'application/json') FileMetadata metadata
  ) {
    // Handles multipart form with 'document' and 'metadata' parts
    return storageService.storeFile(fileData, metadata);
  }
}

Validation Features

  • Content type validation when contentType is specified
  • Size validation with maxSize limit
  • Required part validation

Framework Integration

Processed by RequestPartResolver which handles multipart request parsing.

Inheritance
Annotations
  • @Target.new({TargetKind.parameter})
  • @ResolvedBy(RequestPartResolver())

Constructors

RequestPart({String? value, bool required = true, String? contentType, int? maxSize})
Binds a multipart/form-data request part to a method parameter.
const

Properties

annotationType Type
Returns the annotation _type of this annotation.
no setterinherited
contentType String?
Expected content type of the multipart part.
final
defaultValue String?
Default value to use if the request element is not present.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
maxSize int?
Maximum allowed size of the part in bytes.
final
required bool
Whether the request element is mandatory.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String?
Name of the request element to bind.
finalinherited

Methods

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
override
equals(Object other) bool
Checks whether the given object is logically equivalent to this annotation.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Returns a string representation of this annotation.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited