A single component of a multipart/form-data request, representing either a simple form field or a file upload.
The Part interface abstracts access to both metadata (headers, content type, and field name) and the actual content (bytes or stream) of an uploaded form part. It is a key component of multipart parsing and upload processing in Jetleaf’s HTTP framework.
Overview
Multipart requests are commonly used for file uploads and form submissions where data is split into multiple logical parts, each with its own headers and content body. A Part object provides uniform access to these parts, regardless of whether they originate from a text field, binary file, or streamed input.
Responsibilities
- Provides access to headers such as
Content-DispositionandContent-Type. - Exposes both metadata (name, filename, size) and raw content.
- Supports writing to files, retrieving binary data, and reading as strings.
- Offers cleanup operations for temporary or large uploads stored on disk.
Design Notes
- Implementations must be thread-safe and non-blocking wherever possible.
- Implementations may store large files in temporary disk locations to avoid excessive memory usage.
- The
getInputStream()method (inherited fromInputStreamSource) provides streaming access to content for efficient large-file handling. - Deleting a Part should release any underlying file handles or temporary storage resources.
Example
final part = request.getPart("avatar");
print("Field name: ${part.getName()}");
print("Submitted filename: ${part.getSubmittedFileName()}");
print("Content type: ${part.getContentType()}");
print("Size: ${part.getSize()} bytes");
// Save the uploaded file
await part.write("/uploads/${part.getSubmittedFileName()}");
// Clean up temporary files
await part.delete();
Typical Implementations
MemoryPart: Stores small parts entirely in memory.FilePart: Stores large uploads in a temporary file.StreamingPart: Provides stream-based access for high-throughput uploads.
See Also
InputStreamSource— base interface for streamed content access.- MultipartParser — responsible for constructing
Partinstances from HTTP requests. - HttpRequest — for accessing uploaded parts via request APIs.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delete(
) → Future< void> - Deletes any temporary storage associated with this multipart part.
-
getBytes(
) → Future< Uint8List> - Returns the raw binary content of this part as a Uint8List.
-
getInputStream(
) → InputStream -
Returns a new
InputStreamto read the underlying content.inherited -
getName(
) → String -
Returns the name of this part, as specified in the
nameparameter of theContent-Dispositionheader. -
getSize(
) → int - Returns the total size of this part in bytes.
-
getString(
[Encoding? encoding]) → Future< String> - Returns the content of this part as a string.
-
getSubmittedFileName(
) → String? - Returns the original filename submitted by the client, if present.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
String fileName) → Future< void> - Writes the content of this part to the specified file path.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited