Stream upload problem for binary files without newline #2504
-
client = httpx.Client()
client.put(url=url, data=open("filename", "rb"))When I use httpx to upload a large binary file(>2G), it will lead to OverflowError: string longer than 2147483647 bytes. It is because my binary file don't contain '\n' byte and httpx stream the data with default iterator of the fileobj( I can externally solve this problem by wrapper a custom class extended def __iter__(self) -> Iterator[bytes]:
if self._is_stream_consumed and self._is_generator:
raise StreamConsumed()
self._is_stream_consumed = True
# old
# for part in self._stream:
# yield part
# new
while True:
part = self._stream.read(self.block_size)
if not part:
break
yield partOr some better design could be made. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you take a look at the internals you'll see that we do prefer Lines 50 to 64 in b82fbe2 We didn't get this right in the past, but it was fixed in #1948 |
Beta Was this translation helpful? Give feedback.
httpx.content=...for byte uploads notdata=....If you take a look at the internals you'll see that we do prefer
.read(chunk_size)where possible...httpx/httpx/_content.py
Lines 50 to 64 in b82fbe2