iShare's picture
Update main.py
b474372
raw
history blame
639 Bytes
from fastapi import FastAPI, File, UploadFile
from pydantic import BaseModel
from fastapi import Form
from fastapi.responses import JSONResponse
app = FastAPI()
@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."}