I faced the difficulty of testing api using postman. Through swagger file upload functionality works correctly, I get a saved file on my hard disk. I would like to understan
As mentioned in the response, I could see the key for the file uploaded is missing. Mention the key for the file in body params as file.
My code:
from fastapi import FastAPI, UploadFile, File
app = FastAPI()
@app.post("/file/")
async def create_upload_file(file: UploadFile = File(...)):
return {"filename": file.filename}
Setup in Postman
As stated in https://github.com/tiangolo/fastapi/issues/1653, the parameter name for the file is the key value that you have to use. Before you were using key=file and value=image.png (or whatever). Instead, FastAPI accepts file=image.png. Thus the error, since the file is necessary, but it is not present (at least, the key with that name is not present).
I tested it with Postman v7.16.1
Let me know if you still have problems.