Due to a python bug not all of the interfaces are compatible.
The fastapi.UploadFile type inherits from SpooledTemporaryFile a builtin
which does not specify the abstract for IOBase and does not support the
seekable method which is required for writing to the file sys. There is
some work to fix this:
For now we reach in to the object to try and patch it ourselves.
This will not work for files larger than UploadFile._max_size as the
attributes change:
Due to a python bug not all of the interfaces are compatible.
The
fastapi.UploadFile
type inherits fromSpooledTemporaryFile
a builtin which does not specify the abstract forIOBase
and does not support theseekable
method which is required for writing to the file sys. There is some work to fix this:https://bugs.python.org/issue26175
A fix for this has been merged in into the 3.11 rc so hopefully this will be fixed soon:
https://github.com/python/cpython/commit/78e70be3318bc2ca57dac188061ed35017a0867c
For now we reach in to the object to try and patch it ourselves. This will not work for files larger than
UploadFile._max_size
as the attributes change:https://stackoverflow.com/a/47169185/5006710
We make sure that the object has a large enough size in
increase_max_file_size
When 3.11 rolls out (and we are able to use it)
_fix_bad_spools
andincrease_max_file_size
can be deleted.