Results of 1 - 1 of about 1 for video (0.001 sec.)
- カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 9414
- カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか
...す。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import StreamingResponse app = FastAPI () async def fake_video_streamer (): for i in range ( 10 ): yield b "some fake video bytes" @app . get ( "/" ) async def main (): return Streaming...Response ( fake_video_streamer ()) StreamingResponse をファイルライクなオブジェクトとともに使う ファイルライクなオブジェクト (例えば、 open() で...れています。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import StreamingResponse some_file_path = "large-video-file.mp4" app = FastAPI () @app . get ( "/" ) def main (): def iterfile (): # (1) with open ( some_file_path , mode = "rb"... - https://man.mtool.work/fastapi/0.115/advanced/custom-response/
PREV
1
NEXT