from fastapi import FastAPI
from os import getcwd
from fastapi.responses import FileResponse
app = FastAPI()@router.get("/download/{name_file}")defdownload_file(name_file:str):return FileResponse(path=getcwd()+"/"+ name_file, media_type='application/octet-stream', filename=name_file)
How to get files using FastAPI
from fastapi import FastAPI
from os import getcwd
from fastapi.responses import FileResponse
app = FastAPI()@router.get("/file/{name_file}")defget_file(name_file:str):return FileResponse(path=getcwd()+"/"+ name_file)
How to delete files using FastAPI
from fastapi import FastAPI
from os import getcwd, remove
from fastapi.responses import JSONResponse
app = FastAPI()@router.delete("/delete/file/{name_file}")defdelete_file(name_file:str):try: remove(getcwd()+"/"+ name_file)return JSONResponse(content={"removed":True}, status_code=200)except FileNotFoundError:return JSONResponse(content={"removed":False,"error_message":"File not found"}, status_code=404)