簡體   English   中英

將 Flask 的 api 更改為 Fastapi

[英]Change api of Flask to Fastapi

我正在將在 flask 中創建的 API 更改為 FastAPI,但我不知道如何更改此代碼,任何建議:

@app.route('/download/<fname>', methods=['GET'])
def download(fname):
 return send_file(fname) 

提前致謝。

這完全取決於您要下載的文件類型。 但是你可以在這里找到很好的信息: FastApi Streaming Response

在您的情況下,它將類似於:

from fastapi.responses import StreamingResponse

@app.get("/download")
async def download(fname : str):
 file_like = open(fname, mode="rb")
 return StreamingResponse(file_like, media_type="type of your file")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM