starlette
starlette copied to clipboard
fix: Use anyio.SpooledTemporaryFile in UploadFile
Summary
This PR updates the internal implementation of UploadFile to use anyio.SpooledTemporaryFile[bytes] instead of a generic BinaryIO interface.
By using anyio.SpooledTemporaryFile, all file operations (read, write, seek) are now fully asynchronous and consistent across both in-memory and disk-based file handling. This eliminates the need for run_in_threadpool and simplifies the logic for determining whether the file is in memory or on disk.
This is my first contribution to Starlette. If any part of this PR doesn't follow the project's conventions or needs to be revised or split, Iām more than happy to make the necessary changes.
Checklist
- [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- [x] I've updated the documentation accordingly.