Skip to content

Conversation

@nggit
Copy link
Owner

@nggit nggit commented Jun 20, 2025

Added the part.stream(), a per-part streaming method to make it simpler to use and more intuitive.

# `part` represents a field/file received in a multipart request
async for part in request.files(max_file_size=16384):
    filename = part['filename']
    # ...
    # stream a (possibly) large part in chunks
    async for data in part.stream():
        # ...

    # NOTE: `part['data']` is `pop()`ed and
    # the second `stream()` call on the same `part` is a no-op
    async for data in part.stream():
        raise ValueError  # should not raised!

This change does not break the old way.

# `part` represents a field/file received in a multipart request
async for part in request.files(max_file_size=16384):
    filename = part['filename']
    # ...
    data = part['data']
    # ...
    if part['eof']:
        # end of a multipart field/file
    else:
        # this is a partial file

See the full example: https://github.com/nggit/tremolo/blob/main/examples/upload_and_save.py

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
Image C Reliability Rating on New Code (required ≥ A)
Image C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Image Catch issues before they fail your Quality Gate with our IDE extension Image SonarQube for IDE

@nggit nggit merged commit 71c9ded into main Jun 21, 2025
23 of 24 checks passed
@nggit nggit deleted the multipart branch June 21, 2025 23:31
@nggit nggit mentioned this pull request Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants