> ## Documentation Index
> Fetch the complete documentation index at: https://enterprise-docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# ファイルをアップロード

> **対象アプリ**：Chatflow、Workflow、チャットボット、Agent、テキストジェネレーター。

ファイルをアップロードし、後続のリクエストから参照するための `id` を返します。ファイルはアップロードしたエンドユーザーに属し、同じ `user` を持つリクエストだけがそのファイルを参照できます。

アプリが実際に扱えるファイル種別は、アプリのファイルアップロード設定によって決まります。[アプリケーションのパラメータ情報を取得](/ja/3.11.x/develop/api/applications/get-app-parameters) で確認できます。



## OpenAPI

````yaml /ja/3.11.x/develop/api/openapi_service.json post /files/upload
openapi: 3.0.1
info:
  title: Dify サービス API
  description: >-
    Dify アプリケーションとナレッジベースのための REST API です。アプリケーション系エンドポイントはアプリの API
    キーで、ナレッジ系エンドポイントはナレッジベースの API キーで認証します。
  version: 1.0.0
servers:
  - url: https://{api_base_url}
    description: Dify サービス API のベース URL です。ご利用のデプロイ環境の API ベース URL に置き換えてください。
    variables:
      api_base_url:
        default: api.example.com/v1
        description: API ベース URL のホストとパス（`https://` を除く）。
security:
  - ApiKeyAuth: []
tags:
  - name: チャットメッセージ
    description: チャットメッセージとインタラクションに関連する操作です。
  - name: ファイル操作
    description: ファイルのアップロードとプレビューの操作です。
  - name: エンドユーザー
    description: エンドユーザー情報に関連する操作です。
  - name: メッセージフィードバック
    description: ユーザーフィードバックの操作です。
  - name: 会話管理
    description: 会話管理に関連する操作です。
  - name: 音声・テキスト変換
    description: テキスト読み上げと音声認識の操作です。
  - name: アプリケーション設定
    description: アプリケーション設定と情報を取得する操作です。
  - name: アノテーション管理
    description: ダイレクト返信用のアノテーション管理に関連する操作です。
  - name: 人間の入力
    description: 人間の入力を要する一時停止中のワークフローの再開操作です。
  - name: ワークフロー実行
    description: ワークフローの実行と管理のための操作です。
  - name: 完了メッセージ
    description: テキスト生成に関連する操作です。
  - name: ナレッジベース
    description: ナレッジベースの作成、設定、取得を含むナレッジベース管理の操作です。
  - name: ドキュメント
    description: ナレッジベース内のドキュメントの作成、更新、管理のための操作です。
  - name: チャンク
    description: ドキュメントチャンクと子チャンクの管理のための操作です。
  - name: メタデータ
    description: ナレッジベースのメタデータフィールドとドキュメントメタデータ値の管理のための操作です。
  - name: タグ管理
    description: ナレッジベースタグとタグバインディングの管理のための操作です。
  - name: モデル
    description: 利用可能なモデルを取得するための操作です。
  - name: ナレッジパイプライン
    description: データソースプラグインとパイプライン実行を含むナレッジパイプラインの管理と実行のための操作です。
paths:
  /files/upload:
    post:
      tags:
        - ファイル操作
      summary: ファイルをアップロード
      description: >-
        **対象アプリ**：Chatflow、Workflow、チャットボット、Agent、テキストジェネレーター。


        ファイルをアップロードし、後続のリクエストから参照するための `id` を返します。ファイルはアップロードしたエンドユーザーに属し、同じ
        `user` を持つリクエストだけがそのファイルを参照できます。


        アプリが実際に扱えるファイル種別は、アプリのファイルアップロード設定によって決まります。[アプリケーションのパラメータ情報を取得](/ja/3.11.x/develop/api/applications/get-app-parameters)
        で確認できます。
      operationId: uploadBasicChatFileJa
      requestBody:
        description: ファイルアップロードリクエスト。multipart/form-data 形式が必要です。
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: >-
                    アップロードするファイル。`multipart/form-data` の 1 パートとして送信します。ファイル名に
                    `/` や `\` は使えません。


                    デプロイの安全ブラックリスト（`UPLOAD_FILE_EXTENSION_BLACKLIST`、デフォルトは空）にある拡張子を除き、任意の拡張子を受け付けます。


                    サイズ上限はカテゴリごとに適用されます：画像 10 MB、音声 50 MB、動画 100 MB、その他のファイル 15
                    MB（デフォルト値）。`UPLOAD_*_FILE_SIZE_LIMIT`
                    [環境変数](/ja/3.11.x/deploy/advanced-configuration/environment-variables)
                    で調整できます。
                user:
                  type: string
                  description: >-
                    このアップロードが属するエンドユーザーの識別子。アプリ側で定義し、アプリ内で一意にします。省略すると、共有の
                    `DEFAULT-USER` に帰属します。同じ `user`
                    を持つ後続のリクエストだけがこのファイルを参照できます。[エンドユーザーの識別](/ja/3.11.x/develop/api/guides/end-user-identity)
                    を参照してください。
      responses:
        '201':
          description: ファイルが正常にアップロードされました。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileUploadResponse'
              examples:
                uploadSuccess:
                  summary: Response Example
                  value:
                    id: a1b2c3d4-5678-90ab-cdef-1234567890ab
                    reference: null
                    name: product-photo.png
                    size: 204800
                    extension: png
                    mime_type: image/png
                    created_by: f1e2d3c4-b5a6-7890-abcd-ef1234567890
                    created_at: 1705407629
                    preview_url: null
                    source_url: >-
                      https://upload.dify.ai/files/a1b2c3d4-5678-90ab-cdef-1234567890ab/file-preview?timestamp=1705407629&nonce=8b3e26a5&sign=rN5DXW3xkVGwGE5MSvptu_BhQVXpMbXWmVJ0ib0LMzI=
                    original_url: null
                    user_id: null
                    tenant_id: 11223344-5566-7788-99aa-bbccddeeff00
                    conversation_id: null
                    file_key: null
        '400':
          description: >-
            - `no_file_uploaded` : リクエストにファイルが提供されていません。

            - `too_many_files` : 1 回のリクエストにつき 1 ファイルのみ許可されています。

            - `filename_not_exists_error` : アップロードされたファイルにファイル名がありません。

            - `invalid_param` : ファイル名に `/` または `\`
            が含まれているか、ファイルの拡張子がデプロイのブラックリストにあります。
          content:
            application/json:
              examples:
                no_file_uploaded:
                  summary: no_file_uploaded
                  value:
                    status: 400
                    code: no_file_uploaded
                    message: Please upload your file.
                too_many_files:
                  summary: too_many_files
                  value:
                    status: 400
                    code: too_many_files
                    message: Only one file is allowed.
                filename_not_exists_error:
                  summary: filename_not_exists_error
                  value:
                    status: 400
                    code: filename_not_exists_error
                    message: The specified filename does not exist.
                invalid_param:
                  summary: invalid_param
                  value:
                    status: 400
                    code: invalid_param
                    message: File extension '.exe' is not allowed for security reasons
        '413':
          description: >-
            `file_too_large` : ファイルがカテゴリごとのサイズ上限（`file` フィールドを参照）を超えています。現在、実行時の
            `message` は空文字列で返ります（既知のバックエンドの問題）。`code` とステータスコードで判定してください。
          content:
            application/json:
              examples:
                file_too_large:
                  summary: file_too_large
                  value:
                    status: 413
                    code: file_too_large
                    message: ''
        '415':
          description: '`unsupported_file_type` : アップロードされた `file` パートに MIME タイプが宣言されていません。'
          content:
            application/json:
              examples:
                unsupported_file_type:
                  summary: unsupported_file_type
                  value:
                    status: 415
                    code: unsupported_file_type
                    message: File type not allowed.
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |-
            curl --request POST \
              --url 'https://{api_base_url}/files/upload' \
              --header 'Authorization: Bearer {api_key}' \
              --form 'file=@product-photo.png' \
              --form 'user={user}'
components:
  schemas:
    FileUploadResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: 一意のファイル ID。
        reference:
          type: string
          nullable: true
          description: >-
            Agent
            やツールのコンテキストでファイルを添付する際に内部的に使用される不透明なファイル参照です。このエンドポイントでアップロードされたファイルでは常に
            `null` です。
        name:
          type: string
          description: ファイル名。
        size:
          type: integer
          description: ファイルサイズ（バイト）。
        extension:
          type: string
          nullable: true
          description: ファイル拡張子。
        mime_type:
          type: string
          nullable: true
          description: ファイルの MIME タイプ。
        created_by:
          type: string
          format: uuid
          nullable: true
          description: >-
            アップロードしたエンドユーザーの
            ID。[エンドユーザー取得](/ja/3.11.x/develop/api/end-users/get-end-user-info)
            で詳細を確認できます。
        created_at:
          type: integer
          format: int64
          description: アップロードタイムスタンプ（Unix エポック秒）。
        preview_url:
          type: string
          nullable: true
          description: ファイルのプレビュー URL。
        source_url:
          type: string
          description: ファイルの署名付きダウンロード URL です。
        original_url:
          type: string
          nullable: true
          description: ファイルの元の URL。
        user_id:
          type: string
          format: uuid
          nullable: true
          description: 未使用です。常に `null` になります。
        tenant_id:
          type: string
          format: uuid
          nullable: true
          description: 関連付けられたテナントの ID。
        conversation_id:
          type: string
          format: uuid
          nullable: true
          description: 関連付けられた会話の ID。
        file_key:
          type: string
          nullable: true
          description: 未使用です。常に `null` になります。
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        すべてのリクエストは API キーで認証します：`Authorization: Bearer
        {API_KEY}`。アプリのエンドポイントにはアプリの API キーを、ナレッジのエンドポイントにはナレッジベースの API
        キーを使用します（[Dify API
        クイックスタート](/ja/3.11.x/develop/api/guides/get-started)）。


        キーはサーバーサイドで保管し、クライアントコードには決して埋め込まないでください。キーが欠落または無効なリクエストは HTTP
        `401`（`unauthorized`）で失敗します。

````