How to send MultiPart Request without calling drain?

Viewed 50

Since version 3.0.0 of aiohttp the drain method of StreamResponse was deprecated. But in the documentation of sending multipart request drain method is still used. And it's unobvious how to use write instead of drain in this case. Could someone help out?

my_boundary = 'some-boundary'
response = web.StreamResponse(
    status=200,
    reason='OK',
    headers={
        'Content-Type': 'multipart/x-mixed-replace;boundary={}'.format(my_boundary)
    }
)
while True:
    frame = get_jpeg_frame()
    with MultipartWriter('image/jpeg', boundary=my_boundary) as mpwriter:
        mpwriter.append(frame, {
            'Content-Type': 'image/jpeg'
        })
        await mpwriter.write(response, close_boundary=False)
    await response.drain()  # should it be await response.write_eof() ?
0 Answers
Related