HttpMultipartField
Package: @opra/common
HttpMultipartField describes a single part within a multipart/form-data body — either an uploaded file ('file') or a non-file form field ('field'). It extends HttpMediaType to carry the part's data type and content-type metadata.
Inheritance
DocumentElement
└── HttpMediaType
└── HttpMultipartField
All HttpMediaType properties (type, contentType, maxFileSize, etc.) are inherited. See HttpMediaType.
Additional properties
| Property | Type | Description |
|---|---|---|
fieldName | string | RegExp | The multipart field name, or a RegExp for pattern-based matching. |
fieldType | 'file' | 'field' | Whether this part is an uploaded file or a non-file form field. |
required | boolean | undefined | Whether the part must be present in the request. |
Methods
toJSON(options?)
Returns an OpraSchema.HttpMultipartField plain object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpMultipartField
Accessing multipart field declarations
const op = document.httpApi.findOperation('/customers/:id/avatar', 'uploadAvatar');
const rb = op.requestBody;
const mt = rb?.content[0];
if (mt) {
for (const part of mt.multipartFields) {
console.log(part.fieldName, part.fieldType, part.required);
}
// Find a specific field by name and type
const avatarField = mt.findMultipartField('avatar', 'file');
}