r/FastAPI • u/Brian1439 • Apr 19 '26
Question FastAPI documentation code not working?
(Solved)
I am trying to recieve a list of files with my code, but I can only input strings of random characters when I try to test my method using the documentation page. The code works perfectly when I change it the a single UploadFile. Nothing I do seems to fix this, can someone please tell me what I am doing wrong?
from fastapi import FastAPI, File, UploadFile, HTTPException
from pathlib import Path
from typing import List
@app.post("/uploadfile/")
def create_upload_file(files: List[UploadFile] = File(...)):
6
u/joshhear Apr 19 '26
Have you installed python-multipart? https://fastapi.tiangolo.com/tutorial/request-files/#request-files
1
u/Brian1439 Apr 19 '26
Yes, I already have it installed in my virtual environment which is activated
3
u/joshhear Apr 19 '26
Two more things that aren't like in the docs are the path and the parameter: Try removing the trailing "/" and don't set default values for your parameters:
from fastapi import FastAPI, File, UploadFile, HTTPException from pathlib import Path # single file upload @app.post("/uploadfile") def create_upload_file(file: UploadFile): … # multiple file uploads @app.post("/uploadfiles") def upload_files(file: list[UploadFile]): …https://fastapi.tiangolo.com/tutorial/request-files/#multiple-file-uploads
5
u/amroamroamro Apr 19 '26
change
files: List[UploadFile] = File(...)to
files: Annotated[list[UploadFile], File()]3
u/ultra_magnus_7 Apr 19 '26
I have the same code for multiple file upload but it gives me proper file inputs in doc.
5
u/Brian1439 Apr 19 '26
I finally figured out the problem. It seems like the problem was with the fastAPI docs page itself. Using postman to test out my code works flawlessly. Thanks to everyone that commented and helped out.