upload_test / api.py
scottwangahead's picture
Create api.py
9b5b70e verified
raw
history blame contribute delete
419 Bytes
from fastapi import FastAPI, File, UploadFile
import shutil
import os
app = FastAPI()
@app.post("/upload")
async def upload_file(file: UploadFile = File(...)):
upload_dir = "/tmp/uploads"
os.makedirs(upload_dir, exist_ok=True)
file_path = os.path.join(upload_dir, file.filename)
with open(file_path, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
return {"filename": file.filename}