[英]Change api of Flask to Fastapi
I am changing an API created in a flask to FastAPI, but I don't know how to change this code, any advice:我正在将在 flask 中创建的 API 更改为 FastAPI,但我不知道如何更改此代码,任何建议:
@app.route('/download/<fname>', methods=['GET'])
def download(fname):
return send_file(fname)
Thanks in advance.提前致谢。
It all depends of what kind of file you're trying to download.这完全取决于您要下载的文件类型。 But you can find good information here: FastApi Streaming Response但是你可以在这里找到很好的信息: FastApi Streaming Response
In your case it would be something like:在您的情况下,它将类似于:
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.