Results of 1 - 3 of about 3 for FileResponse (0.001 sec.)
- Additional Responses in OpenAPI 11459
- Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig
...tion/json ) or a PNG image: Python 3.8+ from typing import Union from fastapi import FastAPI from fastapi.responses import FileResponse from pydantic import BaseModel class Item ( BaseModel ): id : str value : str app = FastAPI () @app . get ( "/items/ {item...ON item or an image." , } }, ) async def read_item ( item_id : str , img : Union [ bool , None ] = None ): if img : return FileResponse ( "image.png" , media_type = "image/png" ) else : return { "id" : "foo" , "value" : "there goes my hero" } Note Notice tha...t you have to return the image using a FileResponse directly. Info Unless you specify a different media type explicitly in your responses parameter, FastAPI will assume the r... - https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
- Custom Response Classes - File, HTML, Redirect, Streaming, etc. 9505
- Custom Response Classes - File, HTML, Redirect, Streaming, etc. There are several custom response classes you can use to create an instance and return them directly from your path operations . Read more about it in the FastAPI docs for Cust
...ponse - HTML, Stream, File, others . You can import them directly from fastapi.responses : from fastapi.responses import ( FileResponse , HTMLResponse , JSONResponse , ORJSONResponse , PlainTextResponse , RedirectResponse , Response , StreamingResponse , UJS...und - raw_headers - render - init_headers - headers - set_cookie - delete_cookie Starlette Responses ::: fastapi.responses.FileResponse options: members: - chunk_size - charset - status_code - media_type - body - background - raw_headers - render - init_head... - https://man.mtool.work/fastapi/0.115/reference/responses/
- カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 6920
- カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか
...wait をサポートしていない標準の open() を使っているので、通常の def でpath operationを宣言していることに注意してください。 FileResponse レスポンスとしてファイルを非同期的にストリームします。 他のレスポンスタイプとは異なる引数のセットを受け取りインスタンス化し...ngth 、 Last-Modified 、 ETag ヘッダーが含まれます。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import FileResponse some_file_path = "large-video-file.mp4" app = FastAPI () @app . get ( "/" ) async def main (): return FileResponse ( some_... - https://man.mtool.work/fastapi/0.115/advanced/custom-response/
PREV
1
NEXT