iShare's picture
Create main.py
5ae2a0a
raw
history blame
474 Bytes
@app.post("/file/upload")
async def upload_file(username: str, uploaded_file: UploadFile = File(...)):
path_to_save_file = Path.home() / username / "saved_files"
path_to_save_file.mkdir(parents=True, exist_ok=True)
file_location = f"{path_to_save_file}/{uploaded_file.filename}"
with open(file_location, "wb+") as file_object:
file_object.write(uploaded_file.file.read())
return {"INFO": f"File '{uploaded_file.filename}' saved to your profile."}