kac/server.py

19 lines
486 B
Python

from fastapi import FastAPI, File, UploadFile
from printer import printer
app = FastAPI()
@app.post("/upload")
def upload(file: UploadFile = File(...)):
try:
contents = file.file.read()
with open("image.png", 'wb') as f:
f.write(contents)
except Exception:
return {"message": "There was an error uploading the file"}
finally:
file.file.close()
printer()
return {"message": f"Successfully uploaded {file.filename}"}