Skip to content

Streaming multipart support - #2382

Merged
lovelydinosaur merged 9 commits into
masterfrom
streaming-multipart-support
Dec 12, 2022
Merged

lovelydinosaur merged 9 commits into
masterfrom
streaming-multipart-support

Conversation

@lovelydinosaur

@lovelydinosaur lovelydinosaur commented Sep 30, 2022 •

Copy link
Copy Markdown
Member

Closes #2249

Something we're not currently handling here, that'd also need updating is how we handle non-rewindable cases.

If the file instance is a non-seekable IOBase then we ought to raise a StreamConsumed error if we attempt to read from the file more than once. This occurs if we attempt to upload a streaming multipart file, but then get a redirect. Everything's fine if we've got a rewindable file instance, but if we've got a non-rewindable case then we need to error out, since we can't repeat the upload at that point.


Edit: My description of this ticket wasn't really sufficient, so...

If we have a multipart file upload but cannot determine it's length, then used chunked transfer encoding, instead of reading the entirety of the file into memory in order to determine the Content-Length.

@lovelydinosaur lovelydinosaur added the enhancement New feature or request label Oct 6, 2022
@adriangb

Copy link
Copy Markdown
Contributor

Wouldn't we get the redirect before we start reading files? I would have thought we'd assemble the multipart stuff into an AsyncIterable[bytes] that lazily does work -> if we get redirected we never start pulling from it.

@lovelydinosaur

lovelydinosaur commented Oct 13, 2022 •

Copy link
Copy Markdown
Member Author

Wouldn't we get the redirect before we start reading files?

Nope. You send the complete request, then you get the complete response.

If the response is a redirect, then you need to send the complete request again. (Which is fine if you're sending a file since you can just rewind to the start, but isn't recoverable if you're eg. streaming some data from a generator)

@ghost

ghost commented Dec 1, 2022

Copy link
Copy Markdown

Any update when this will be added?

@lovelydinosaur

Copy link
Copy Markdown
Member Author

@justinjeffery-ipf This pull request is currently awaiting a review. If you'd like I can send you an invite to the GitHub organisation, which would mean you'd have permission to make approving reviews?

@zanieb zanieb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lovelydinosaur
lovelydinosaur merged commit b97c059 into master Dec 12, 2022
@lovelydinosaur
lovelydinosaur deleted the streaming-multipart-support branch December 12, 2022 16:14
@adriangb

Copy link
Copy Markdown
Contributor

Awesome thanks Tom and Michael!

@lovelydinosaur lovelydinosaur mentioned this pull request Dec 20, 2022
@ghost ghost mentioned this pull request Jan 3, 2023
samclearman pushed a commit to titanmsp/httpx that referenced this pull request Apr 26, 2025
* Streaming multipart support

* Update tests for streaming multipary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

Add support for streaming multipart/form-data

3 participants