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.