|
from fastapi import FastAPI, Request, Query, Path |
|
from fastapi.responses import StreamingResponse, HTMLResponse |
|
from fastapi.middleware.cors import CORSMiddleware |
|
import httpx |
|
import base64 |
|
import io |
|
|
|
app = FastAPI(docs_url=None, redoc_url=None) |
|
|
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=["*"], |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
|
|
|
|
@app.get("/img/{img_base64}", summary="图片显示", tags=["image"]) |
|
async def img(img_base64: str = Path(..., description="图片远程UR的base64加密代码")): |
|
""" |
|
显示远程地址的图片: |
|
|
|
- **img_base64**: 图片远程UR的base64加密代码 |
|
""" |
|
img_url = base64.b64decode(img_base64).decode() |
|
r = httpx.get(img_url) |
|
return StreamingResponse(io.BytesIO(r.content), media_type="image/png") |