Skip to content

Add chunked upload documentation for rx.upload_files_chunk#6259

Merged
masenf merged 4 commits intoreflex-dev:mainfrom
FarhanAliRaza:chunked-upload-docs
Apr 1, 2026
Merged

Add chunked upload documentation for rx.upload_files_chunk#6259
masenf merged 4 commits intoreflex-dev:mainfrom
FarhanAliRaza:chunked-upload-docs

Conversation

@FarhanAliRaza
Copy link
Copy Markdown
Collaborator

Document the new rx.upload_files_chunk API for incremental large file uploads, including handler requirements, chunk properties, and a complete code example. Update the progress section and API routes overview to cover both upload methods.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

closes #6207

Document the new rx.upload_files_chunk API for incremental large file
uploads, including handler requirements, chunk properties, and a
complete code example. Update the progress section and API routes
overview to cover both upload methods.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 31, 2026

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing FarhanAliRaza:chunked-upload-docs (dfafc86) with main (57119bc)

Open in CodSpeed

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 31, 2026

Greptile Summary

This PR documents the new rx.upload_files_chunk / rx.UploadChunkIterator API for streaming large-file uploads incrementally. It adds a "Chunked Uploads" section to the upload reference page, updates the Progress section to cover both upload methods (the simplified three-key progress dict is correct per the current XHR-based frontend), and amends the API-routes overview to mention both upload helpers.

Key changes:

  • New "Chunked Uploads for Large Files" sub-section with step-by-step requirements (@rx.event(background=True), rx.UploadChunkIterator, full-consumption rule) and a complete working code example.
  • Progress-dictionary example correctly simplified to loaded, total, progress — matching the actual xhr.upload.onprogress payload in upload.js.
  • /_upload route documentation updated to list both rx.upload_files and rx.upload_files_chunk.

Issues found:

  • Unintended reflex-web submodule — a broken gitlink is being added at the repository root with no .gitmodules entry. This is unrelated to the docs change and must be removed before merging.
  • \"r+b\" open mode in example code — if the same filename is uploaded more than once, existing bytes beyond the new upload size are not truncated, producing a silently corrupt file. The simpler \"wb\" mode is safer for a documentation example.

Confidence Score: 4/5

Not safe to merge as-is: the broken reflex-web submodule must be removed before merging.

One P1 finding (broken orphan submodule with no .gitmodules) must be fixed before merging. The P2 finding (stale bytes in example code) is a documentation-quality issue that should ideally also be addressed. Once both are resolved the PR is ready.

The reflex-web submodule entry at the repo root must be removed with git rm --cached reflex-web. The reflex/docs/library/forms/upload.md example should also switch from "r+b" to "wb".

Important Files Changed

Filename Overview
reflex-web Broken git submodule entry (mode 160000) added without a .gitmodules file — unrelated to the docs change and should be removed.
reflex/docs/library/forms/upload.md Main documentation update adding chunked-upload section; chunk properties and lifecycle are accurate, but the file-open example uses "r+b" mode which can leave stale bytes when the same filename is re-uploaded with shorter content.
reflex/docs/api-routes/overview.md Small, correct update noting that the /_upload route now covers both rx.upload_files and rx.upload_files_chunk.

Sequence Diagram

sequenceDiagram
    participant Browser
    participant UploadJS as upload.js (XHR)
    participant UploadRoute as /_upload route
    participant ChunkParser as _UploadChunkMultipartParser
    participant ChunkIter as UploadChunkIterator
    participant Handler as handle_large_upload (background)

    Browser->>UploadJS: on_click → rx.upload_files_chunk(upload_id)
    UploadJS->>UploadRoute: POST multipart/form-data (streaming)
    UploadRoute->>ChunkIter: create UploadChunkIterator
    UploadRoute->>Handler: dispatch @rx.event(background=True) with chunk_iter
    UploadRoute->>ChunkParser: parse(stream, chunk_iter)

    loop for each network packet
        ChunkParser->>ChunkIter: push(UploadChunk{filename, offset, content_type, data})
        ChunkIter-->>Handler: yield chunk
        Handler->>Handler: seek(chunk.offset) + write(chunk.data)
    end

    ChunkParser->>ChunkIter: finish()
    Handler->>Handler: close file handles
    Handler->>Handler: async with self → update state

    UploadJS-->>Browser: on_upload_progress({loaded, total, progress})
Loading

Reviews (1): Last reviewed commit: "Add chunked upload documentation for rx...." | Re-trigger Greptile

Your event handler should be an async function that accepts a single argument,
`files: list[UploadFile]`, which will contain [FastAPI UploadFile](https://fastapi.tiangolo.com/tutorial/request-files) instances.
You can read the files and save them anywhere as shown in the example.
For uploads, your event handler should be an async function that accepts a single argument, `files: list[UploadFile]`, which will contain [FastAPI UploadFile](https://fastapi.tiangolo.com/tutorial/request-files) instances. You can read the files and save them anywhere as shown in the example.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

while we're in here, lets change this to Starlette's UploadFile, since that's closer to what we're using.

but probably should include the generated docs for our UploadFile class eventually, since that is what we actually use

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated.

Comment on lines +465 to +467
Use `rx.upload_files_chunk(...)` when files may be large or when you want the
backend to write data incrementally instead of waiting for the full upload
before the handler starts.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i know you say "large" here, but i would explicitly mention something about memory consumption being higher when buffering files

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated.

@masenf masenf merged commit 1e91dea into reflex-dev:main Apr 1, 2026
6 checks passed
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.

Documentation for rx.upload_file_chunk

2 participants