You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, it seems like it is only possible to figure out what Content-Length is by buffering the data to be sent.
In my situation, sometimes I have a large file on disk with a known size beforehand which I would like to include in a multi-part post request. The documentation also discusses "streaming uploads:"
It would be nice if I could combine these solutions:
multi-part post request
Content-Length for the whole request
streaming upload
Currently, (1) and (2) can be achieved using aiohttp.FormData with file-like objects, but using io.IOBase should be avoided because we are calling blocking IO inside an async context.
Describe the solution you'd like
aiohttp.FormData.add_field should be extended in two ways:
support being given AsyncIterable[bytes] as value
accept optional parameter content_length which, if given, manually sets the length of the part.
When trying to send the FormData: if the lengths of all parts are known, then set the header Content-Length.
Describe alternatives you've considered
Currently I am using aiohttp.FormData with file-like objects and accepting the performance penalty. If the files get too large, I will write a custom multi-part deserializer, hard-coding its parts into a string template and calculating the Content-Length manually. The hard-coded parts plus file "stream" would be wrapped similarly to how it's done here: #3598 (comment)
Related component
Client
Additional context
No response
Code of Conduct
I agree to follow the aio-libs Code of Conduct
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem?
Oh, the terrors of the internet.
The backend I am working with requires Content-Length to be specified for the whole multipart request, which is discussed in the documentation here:
https://docs.aiohttp.org/en/stable/multipart.html#hacking-multipart
However, it seems like it is only possible to figure out what Content-Length is by buffering the data to be sent.
In my situation, sometimes I have a large file on disk with a known size beforehand which I would like to include in a multi-part post request. The documentation also discusses "streaming uploads:"
https://docs.aiohttp.org/en/stable/client_quickstart.html#streaming-uploads
It would be nice if I could combine these solutions:
Currently, (1) and (2) can be achieved using
aiohttp.FormData
with file-like objects, but usingio.IOBase
should be avoided because we are calling blocking IO inside an async context.Describe the solution you'd like
aiohttp.FormData.add_field
should be extended in two ways:AsyncIterable[bytes]
as valuecontent_length
which, if given, manually sets the length of the part.When trying to send the
FormData
: if the lengths of all parts are known, then set the header Content-Length.Describe alternatives you've considered
Currently I am using
aiohttp.FormData
with file-like objects and accepting the performance penalty. If the files get too large, I will write a custom multi-part deserializer, hard-coding its parts into a string template and calculating the Content-Length manually. The hard-coded parts plus file "stream" would be wrapped similarly to how it's done here: #3598 (comment)Related component
Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: