0

I'm using FastAPI and I want to receive files into memory and not onto disk and then re-read them from disk.

My current endpoint looks like this:

async def upload_file(files: List[UploadFile] = File(...):
    pass

Problems I've encountered while searching for a solution

  • I need UploadFile and not bytes as suggested here, since I need to know the content_type property of the files.
  • I've tried to find a way to access the SpooledFile attrribute max-size to allow memory storage up to this size like written in this Python doc, but to no effect.

Thanks in advance! :)

TheClockTwister
  • 713
  • 6
  • 20
  • Please have a look at [How to Upload File using FastAPI?](https://stackoverflow.com/a/70657621/17865804) – Chris May 01 '22 at 10:55
  • Thanks for the fast reply! Does it always upload to memory as long as the memory is large enough? Example: If I have 8GB RAM, does it upload a 6GB file into memory and not onto disk? – TheClockTwister May 01 '22 at 13:15
  • Does this answer your question? [FastAPI UploadFile is slow compared to Flask](https://stackoverflow.com/questions/65342833/fastapi-uploadfile-is-slow-compared-to-flask) – Chris May 06 '22 at 20:23

0 Answers0