Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 38 for FileResponse (0.07 seconds)

  1. docs/en/docs/advanced/json-base64-bytes.md

    ## Base64 vs Files { #base64-vs-files }
    
    Consider first if you can use [Request Files](../tutorial/request-files.md) for uploading binary data and [Custom Response - FileResponse](./custom-response.md#fileresponse--fileresponse-) for sending binary data, instead of encoding it in JSON.
    
    JSON can only contain UTF-8 encoded strings, so it can't contain raw bytes.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 2.4K bytes
    - Click Count (0)
  2. docs/zh-hant/docs/advanced/json-base64-bytes.md

    如果你的應用需要收發 JSON 資料,但其中需要包含二進位資料,你可以將它以 base64 編碼。
    
    ## Base64 與檔案 { #base64-vs-files }
    
    請先考慮是否能用 [請求檔案](../tutorial/request-files.md) 來上傳二進位資料,並用 [自訂回應 - FileResponse](./custom-response.md#fileresponse--fileresponse-) 來傳送二進位資料,而不是把它們編碼進 JSON。
    
    JSON 只能包含 UTF-8 編碼的字串,因此無法直接包含原始位元組。
    
    Base64 可以把二進位資料編碼成字串,但為此會使用比原始二進位資料更多的字元,因此通常比直接使用檔案來得沒那麼有效率。
    
    只有在確實必須把二進位資料包含在 JSON 裡,且無法改用檔案時,才使用 base64。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:33:04 GMT 2026
    - 2.4K bytes
    - Click Count (0)
  3. docs/zh/docs/advanced/json-base64-bytes.md

    如果你的应用需要接收和发送 JSON 数据,但其中需要包含二进制数据,可以将其编码为 base64。
    
    ## Base64 与文件 { #base64-vs-files }
    
    请先考虑是否可以使用 [请求文件](../tutorial/request-files.md) 来上传二进制数据,并使用 [自定义响应 - FileResponse](./custom-response.md#fileresponse--fileresponse-) 来发送二进制数据,而不是把它编码进 JSON。
    
    JSON 只能包含 UTF-8 编码的字符串,因此无法直接包含原始字节。
    
    Base64 可以把二进制数据编码为字符串,但为此会使用比原始二进制更多的字符,因此通常比直接使用文件的效率更低。
    
    仅当你确实需要在 JSON 中包含二进制数据且无法使用文件时,才使用 base64。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:29:48 GMT 2026
    - 2.4K bytes
    - Click Count (0)
  4. docs/ja/docs/advanced/json-base64-bytes.md

    ## Base64 とファイル { #base64-vs-files }
    
    バイナリデータのアップロードにはまず、JSON にエンコードする代わりに [Request Files](../tutorial/request-files.md) を、バイナリデータの送信には [カスタムレスポンス - FileResponse](./custom-response.md#fileresponse--fileresponse-) を使えるか検討してください。
    
    JSON は UTF-8 でエンコードされた文字列のみを含められるため、生のバイト列は含められません。
    
    Base64 はバイナリデータを文字列にエンコードできますが、そのために元のバイナリより多くの文字を使用する必要があり、通常は通常のファイルより非効率です。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 19 18:55:22 GMT 2026
    - 3.1K bytes
    - Click Count (0)
  5. fastapi/responses.py

    from typing import Any
    
    from fastapi.exceptions import FastAPIDeprecationWarning
    from fastapi.sse import EventSourceResponse as EventSourceResponse  # noqa
    from starlette.responses import FileResponse as FileResponse  # noqa
    from starlette.responses import HTMLResponse as HTMLResponse  # noqa
    from starlette.responses import JSONResponse as JSONResponse  # noqa
    from starlette.responses import PlainTextResponse as PlainTextResponse  # noqa
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Mar 01 09:21:52 GMT 2026
    - 3.6K bytes
    - Click Count (0)
  6. docs/en/docs/advanced/custom-response.md

    If you are streaming JSON Lines, follow the [Stream JSON Lines](../tutorial/stream-json-lines.md) tutorial.
    
    ///
    
    ### `FileResponse` { #fileresponse }
    
    Asynchronously streams a file as the response.
    
    Takes a different set of arguments to instantiate than the other response types:
    
    * `path` - The file path to the file to stream.
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 11K bytes
    - Click Count (0)
  7. docs/zh-hant/docs/advanced/custom-response.md

    ///
    
    /// tip
    
    與其直接回傳 `StreamingResponse`,你大概會想遵循[資料串流](./stream-data.md)中的作法,這樣更方便,並且會在底層幫你處理取消。
    
    如果你要串流 JSON Lines,請參考教學:[串流 JSON Lines](../tutorial/stream-json-lines.md)。
    
    ///
    
    ### `FileResponse` { #fileresponse }
    
    以非同步串流方式將檔案作為回應。
    
    它在初始化時所需的參數與其他回應型別不同:
    
    - `path` - 要串流的檔案路徑。
    - `headers` - 要包含的自訂標頭,字典形式。
    - `media_type` - 描述 media type 的字串。若未設定,將根據檔名或路徑推斷 media type。
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 10.3K bytes
    - Click Count (0)
  8. docs/en/docs/advanced/additional-responses.md

    {* ../../docs_src/additional_responses/tutorial002_py310.py hl[17:22,26] *}
    
    /// note
    
    Notice that you have to return the image using a `FileResponse` directly.
    
    ///
    
    /// info
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 8.8K bytes
    - Click Count (0)
  9. docs/zh/docs/advanced/additional-responses.md

    例如,你可以添加一个额外的媒体类型 `image/png`,声明你的*路径操作*可以返回 JSON 对象(媒体类型为 `application/json`)或 PNG 图片:
    
    {* ../../docs_src/additional_responses/tutorial002_py310.py hl[17:22,26] *}
    
    /// note | 注意
    
    请注意,你必须直接使用 `FileResponse` 返回图片。
    
    ///
    
    /// info | 信息
    
    除非你在 `responses` 参数中明确指定不同的媒体类型,否则 FastAPI 会假设响应与主响应类具有相同的媒体类型(默认是 `application/json`)。
    
    但是如果你指定了一个媒体类型为 `None` 的自定义响应类,FastAPI 会对任何具有关联模型的附加响应使用 `application/json`。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 8.7K bytes
    - Click Count (0)
  10. docs/ja/docs/advanced/additional-responses.md

    例えば、`image/png` の追加メディアタイプを加え、あなたの *path operation* が JSON オブジェクト(メディアタイプ `application/json`)または PNG 画像を返せることを宣言できます:
    
    {* ../../docs_src/additional_responses/tutorial002_py310.py hl[17:22,26] *}
    
    /// note | 備考
    
    画像は `FileResponse` を使って直接返す必要がある点に注意してください。
    
    ///
    
    /// info | 情報
    
    `responses` パラメータで明示的に別のメディアタイプを指定しない限り、FastAPI はレスポンスがメインのレスポンスクラスと同じメディアタイプ(デフォルトは `application/json`)であるとみなします。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:07:17 GMT 2026
    - 10K bytes
    - Click Count (0)
Back to Top