1

I'm using FastAPI as backend, while handling file uploading request, got 422 error.

This is the front-end code.

const formData = new FormData()
formData.append("file", note.file[0])
formData.append("name", "John Doe")
formData.append("email", "johndoe@example.com")

const response = await axios.post(url, formData)

This is the back-end code.

def create_course(file: UploadFile = File(...), name: str = Form(...), email: str = Form(...), db: Session = Depends(get_db), user: dict = Depends(get_current_user)):
    ...
    return {"success":"true"}

Without file, it's working. But if I add file to the formData, it returns error.

Robert
  • 7,394
  • 40
  • 45
  • 64
Lilo Lange
  • 11
  • 1
  • Please have a look at [this](https://stackoverflow.com/a/70640522/17865804), as well as [this](https://stackoverflow.com/a/72029319/17865804), [this](https://stackoverflow.com/a/70824288/17865804) and [this](https://stackoverflow.com/a/74507628/17865804) – Chris Jul 21 '23 at 04:04

0 Answers0