# Multipart reference

class aiohttp.MultipartResponseWrapper(resp, stream)

  Wrapper around the `MultipartReader` to take care about underlying connection and close it when it needs in.

  at_eof()

    Returns `True` when all response data had been read.

    Return type:

      bool

  async next()

    Emits next multipart reader object.

  async release()

    Releases the connection gracefully, reading all the content to the void.

class aiohttp.BodyPartReader(boundary, headers, content)

  Multipart reader for single body part.

  async read(*, decode=False)

    Reads body part data.

    Parameters:

      decode (bool) – Decodes data following by encoding method from `Content-Encoding` header. If it missed data remains untouched

    Return type:

      bytearray

  async read_chunk(size=chunk_size)

    Reads body part content chunk of the specified size.

    Parameters:

      size (int) – chunk size

    Return type:

      bytearray

  async readline()

    Reads body part by line by line.

    Return type:

      bytearray

  async release()

    Like `read()`, but reads all the data to the void.

    Return type:

      None

  async text(*, encoding=None)

    Like `read()`, but assumes that body part contains text data.

    Parameters:

      encoding (str) – Custom text encoding. Overrides specified in charset param of `Content-Type` header

    Return type:

      str

  async json(*, encoding=None)

    Like `read()`, but assumes that body parts contains JSON data.

    Parameters:

      encoding (str) – Custom JSON encoding. Overrides specified in charset param of `Content-Type` header

  async form(*, encoding=None)

    Like `read()`, but assumes that body parts contains form urlencoded data.

    Parameters:

      encoding (str) – Custom form encoding. Overrides specified in charset param of `Content-Type` header

  at_eof()

    Returns `True` if the boundary was reached or `False` otherwise.

    Return type:

      bool

  decode(data)

    Decodes data synchronously according the specified `Content-Encoding` or `Content-Transfer-Encoding` headers value.

    Supports `gzip`, `deflate` and `identity` encodings for `Content-Encoding` header.

    Supports `base64`, `quoted-printable`, `binary` encodings for `Content-Transfer-Encoding` header.

    Parameters:

      data (bytearray) – Data to decode.

    Raises:

      `RuntimeError` - if encoding is unknown.

    Return type:

      bytes

    Note

    For large payloads, consider using `decode_iter()` instead to avoid blocking the event loop during decompression.

  async decode_iter(data)

    Decodes data asynchronously according the specified `Content-Encoding` or `Content-Transfer-Encoding` headers value.

    This is an async iterator and will return decoded data in chunks. This can be used to avoid loading large payloads into memory.

    This method offloads decompression to an executor for large payloads to avoid blocking the event loop.

    Supports `gzip`, `deflate` and `identity` encodings for `Content-Encoding` header.

    Supports `base64`, `quoted-printable`, `binary` encodings for `Content-Transfer-Encoding` header.

    Parameters:

      data (bytearray) – Data to decode.

    Raises:

      `RuntimeError` - if encoding is unknown.

    Return type:

      bytes

    Added in version 3.13.4.

  get_charset(default=None)

    Returns charset parameter from `Content-Type` header or default.

  name

    A field name specified in `Content-Disposition` header or `None` if missed or header is malformed.

    Readonly `str` property.

  filename

    A field filename specified in `Content-Disposition` header or `None` if missed or header is malformed.

    Readonly `str` property.

class aiohttp.MultipartReader(headers, content)

  Multipart body reader.

  classmethod from_response(cls, response)

    Constructs reader instance from HTTP response.

    Parameters:

      response – `ClientResponse` instance

  at_eof()

    Returns `True` if the final boundary was reached or `False` otherwise.

    Return type:

      bool

  async next()

    Emits the next multipart body part.

  async release()

    Reads all the body parts to the void till the final boundary.

  async fetch_next_part()

    Returns the next body part reader.

class aiohttp.MultipartWriter(subtype='mixed', boundary=None, close_boundary=True)

  Multipart body writer.

  `boundary` may be an ASCII-only string.

  boundary

    The string (`str`) representation of the boundary.

    Changed in version 3.0: Property type was changed from `bytes` to `str`.

  append(obj, headers=None)

    Append an object to writer.

  append_payload(payload)

    Adds a new body part to multipart writer.

  append_json(obj, headers=None)

    Helper to append JSON part.

  append_form(obj, headers=None)

    Helper to append form urlencoded part.

  size

    Size of the payload.

  async write(writer, close_boundary=True)

    Write body.

    Parameters:

      close_boundary (bool) – The (`bool`) that will emit boundary closing. You may want to disable when streaming (`multipart/x-mixed-replace`)

    Added in version 3.4: Support `close_boundary` argument.