parts property

Stream<Multipart> parts

Reads parts of this multipart request.

Each part is represented as a MimeMultipart, which implements the Stream interface to emit chunks of data. Headers of a part are available through MimeMultipart.headers.

Parts can be processed by listening to this stream, as shown in this example:

await for (final part in request.parts) {
  final headers = part.headers;
  final content = utf8.decoder.bind(part).first;
}

Listening to this stream will read this request, which may only be done once.

Throws a StateError if this is not a multipart request (as reported through isMultipart). The stream will emit a MimeMultipartException if the request does not contain a well-formed multipart body.

Implementation

Stream<Multipart> get parts {
  final boundary = _extractMultipartBoundary();
  if (boundary == null) {
    throw StateError('Not a multipart request.');
  }

  return MimeMultipartTransformer(boundary)
      .bind(read())
      .map((part) => Multipart(this, part));
}