I defined this endpoint using FastAPI:
@app.post("/detect/")
def predict(request: Request, file: bytes = File(...)):
return f"Filename is {file.name}"
and I am testing that endpoint this way:
url = "http://127.0.0.1:8000/detect"
file = 'myimage.jpg'
f = open(file, 'rb')
files = {"file": (f.name, f, "multipart/form-data")}
response = requests.request("POST", url, files=files)
print(response.text)
So, I would like the response to be "Filename is myimage.jpg", but file.name
is not defined.
Which is the correct way to get the file name inside the endpoint? I know I can use UploadFile
instead of bytes, but in this particular case, I would like to keep bytes
because of other operations I need to do inside the endpoint.