set type hint Optional[List[str]], but receive value as ['a,b,c'], not ['a', 'b', 'c'] #6727
-
|
There is the steps:
from typing import Optional
from fastapi import FastAPI, File, UploadFile, Form
from typing import List
app = FastAPI()
@app.post("/")
async def root(category: Optional[List[str]] = Form(..., title="category"), file: UploadFile = File(..., title="uploaded file")):
params = locals()
return {"params": repr(params)}
I'd like to get |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
You're passing 'a,b,c' in the same category Form "field". You would need to pass the three letter in three distinct form fields, all of them named 'category'. For example, the following cURL should work $ curl -X 'POST' \
> 'http://127.0.0.1:8000/' \
> -H 'accept: application/json' \
> -H 'Content-Type: multipart/form-data' \
> -F 'category=a' \
> -F 'category=b' \
> -F 'category=c' \
> -F 'file=@check.html;type=text/html' |
Beta Was this translation helpful? Give feedback.
-
|
@hellocoldworld Thanks. I should change the way to send the request. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here @hellocoldworld ! 👏 🙇 Thanks for reporting back and closing the issue @shizidushu 👍
|
Beta Was this translation helpful? Give feedback.

You're passing 'a,b,c' in the same category Form "field". You would need to pass the three letter in three distinct form fields, all of them named 'category'. For example, the following cURL should work