starlette icon indicating copy to clipboard operation
starlette copied to clipboard

fix: Use anyio.SpooledTemporaryFile in UploadFile

Open 11kkw opened this issue 8 months ago • 0 comments

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.

11kkw avatar Apr 16 '25 03:04 11kkw