Replies: 2 comments
-
Agree that it would be useful and sometimes necessary to be able to use an UploadFile in a background task. For me it is necessary as customers sometimes upload large files that take a long time to process so cannot hold up response waiting for that processing to finish. Also would like to avoid deep copying the file. |
Beta Was this translation helpful? Give feedback.
-
What I did eventually for my case was to not use But what I am guessing is that FastAPI could only guarantee that this I think FastAPI allowing this to happen pre Maybe there should be an explicit method on I am no expert in this and I could very well be misunderstanding how FastAPI actually handles uploaded files. So sorry for any mistakes, but I hope it leads to more discussions. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
As discussed in the issue #10857. The file used to be open when executing the
do_sth_with_the_file
function. But it gets closed in recent versions of FastAPI.I created a workaround using
copy.deepcopy
:As a friend of mine pointed out, maybe it is not a good idea to process the file in background at all. But anyway, the result was a bit surprising to me. Maybe it is worth mentioning in the documentation?
I'd like to help anyone who would stumble upon the same issue. But I don't know if coping is the way to go, or doing something completely different.
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.108.0
Pydantic Version
2.5.3
Python Version
Python 3.12.1
Additional Context
#10857
Beta Was this translation helpful? Give feedback.
All reactions