How to Download Files using FastAPI
To download a file using FastAPI, use the following code:
from fastapi import FastAPI
from fastapi.responses import FileResponse
import uvicorn
app = FastAPI()
@app.get("/download-file")
def download_file():
file_path = "/home/abc/videos/movie1.mp4"
return FileResponse(path=file_path, filename=file_path)
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=8005)
print("running")