Multipart reference¶
- class aiohttp.MultipartResponseWrapper(resp, stream)¶
Wrapper around the
MultipartReaderto take care about underlying connection and close it when it needs in.- at_eof()¶
Returns
Truewhen 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)[source]¶
Multipart reader for single body part.
- async read(*, decode=False)[source]¶
Reads body part data.
- Parameters:
decode (bool) – Decodes data following by encoding method from
Content-Encodingheader. If it missed data remains untouched- Return type:
bytearray
- async read_chunk(size=chunk_size)[source]¶
Reads body part content chunk of the specified size.
- Parameters:
size (int) – chunk size
- Return type:
bytearray
- async text(*, encoding=None)[source]¶
Like
read(), but assumes that body part contains text data.- Parameters:
encoding (str) – Custom text encoding. Overrides specified in charset param of
Content-Typeheader- Return type:
str
- async json(*, encoding=None)[source]¶
Like
read(), but assumes that body parts contains JSON data.- Parameters:
encoding (str) – Custom JSON encoding. Overrides specified in charset param of
Content-Typeheader
- async form(*, encoding=None)[source]¶
Like
read(), but assumes that body parts contains form urlencoded data.- Parameters:
encoding (str) – Custom form encoding. Overrides specified in charset param of
Content-Typeheader
- decode(data)[source]¶
Decodes data synchronously according the specified
Content-EncodingorContent-Transfer-Encodingheaders value.Supports
gzip,deflateandidentityencodings forContent-Encodingheader.Supports
base64,quoted-printable,binaryencodings forContent-Transfer-Encodingheader.- 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)[source]¶
Decodes data asynchronously according the specified
Content-EncodingorContent-Transfer-Encodingheaders 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,deflateandidentityencodings forContent-Encodingheader.Supports
base64,quoted-printable,binaryencodings forContent-Transfer-Encodingheader.- Parameters:
data (bytearray) – Data to decode.
- Raises:
RuntimeError- if encoding is unknown.- Return type:
bytes
Added in version 3.13.4.
- name¶
A field name specified in
Content-Dispositionheader orNoneif missed or header is malformed.Readonly
strproperty.
- filename¶
A field filename specified in
Content-Dispositionheader orNoneif missed or header is malformed.Readonly
strproperty.
- class aiohttp.MultipartReader(headers, content)[source]¶
Multipart body reader.
- classmethod from_response(cls, response)[source]¶
Constructs reader instance from HTTP response.
- Parameters:
response –
ClientResponseinstance
- class aiohttp.MultipartWriter(subtype='mixed', boundary=None, close_boundary=True)[source]¶
Multipart body writer.
boundarymay be an ASCII-only string.- boundary¶
The string (
str) representation of the boundary.Changed in version 3.0: Property type was changed from
bytestostr.
- size¶
Size of the payload.