This is a reminder when I tried to upload multiple images to fastapi's backend server from the normal html <input type =" file "...>
tag instead of using js.
index.html
<html>
<head>
<title>Face Swap App</title>
</head>
<body>
<h1>Look ma! HTML!</h1>
<form enctype="multipart/form-data" method="post" action="swap">
<input type="file" id="source" name="file"></input>
<input type="file" id="target" name="file"></input>
<input type="submit" value="Face Swap">
</form>
</body>
</html>
main.py
@app.post("/swap", response_class=HTMLResponse)
async def create_swapped_image(files: List[UploadFile] = File(...)):
print(files)
return """
<html>
<head>
<title>Face Swap App</title>
</head>
<body>
<h1>Success!</h1>
</body>
</html>
"""
In conclusion, it seems that the name of the input
tag needs to be the same as the argument of the function of the fastapi endpoint! In other words, the input of index.html
index.html
<input type="file" id="source" name="files">
<input type="file" id="target" name="files">
It was solved by changing to. I haven't read all of them, but I don't remember writing this in the official doc, so I thought it would be difficult to understand. I'm sorry if I wrote it ...
Recommended Posts