@app.post("/upload_files") async def upload_file(file: UploadFile): try: if not os.path.exists("uploads"): os.mkdir("uploads") if os.path.exists(f"uploads/{file.filename}"): return {"file_exist": "file already in folder"} with open(f"uploads/{file.filename}", 'wb') as f: f.write(file.file.read()) except Exception as e: return {"Other Error": str(e)} check my endpoint for file upload
Another excellent video
the final error is because you were is hitting "/upload files/" instead of "/uploadfile/" in
@app.post("/upload_files")
async def upload_file(file: UploadFile):
try:
if not os.path.exists("uploads"):
os.mkdir("uploads")
if os.path.exists(f"uploads/{file.filename}"):
return {"file_exist": "file already in folder"}
with open(f"uploads/{file.filename}", 'wb') as f:
f.write(file.file.read())
except Exception as e:
return {"Other Error": str(e)}
check my endpoint for file upload