Create app.py
Browse files123456789101112131415161718192021222324from fastapi import FastAPI, File, UploadFilefrom fastapi.responses import FileResponseimport osimport shutil
app = FastAPI()
# Directory to store uploaded filesUPLOAD_DIR = "/app/uploads"os.makedirs(UPLOAD_DIR, exist_ok=True)
@app.post("/upload/")async def upload_file(file: UploadFile = File(...)): 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}
@app.get("/download/{filename}")async def download_file(filename: str): file_path = os.path.join(UPLOAD_DIR, filename) if os.path.exists(file_path): return FileResponse(file_path, media_type='application/octet-stream', filename=filename) return {"error": "File not found"}app.pyAdded+24