| 1234567891011121314151617181920212223242526 |
- # -*- coding: utf-8 -*-
- # pip install fastapi uvicorn
- from fastapi import FastAPI, HTTPException
- from fastapi.responses import FileResponse
- from pathlib import Path
- import os
- app = FastAPI()
- xml_folder_path = Path("/mnt/xml_file")
- @app.get("/{filename}")
- async def read_xml(filename: str):
- file_path = xml_folder_path / f"{filename}.xml"
- if not file_path.is_file():
- raise HTTPException(status_code=404, detail="File not found")
- return FileResponse(file_path, media_type="application/xml")
- if __name__ == "__main__":
- import uvicorn
- uvicorn.run(app, host="0.0.0.0", port=8000)
|