> ## 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.

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

> **対象アプリ**：Workflow、Chatflow。

この環境のこのアプリへのリクエストで使うファイルをアップロードします。

返される `id` が使えるのは、同じ `user` を持ち、同じアプリと環境に対するリクエストだけです。1 回の実行が参照できるファイルは最大 100 個です。

**標準 API の対応する操作**：[ファイルをアップロード](/ja/3.13.x/develop/api/files/upload-file)。相違点は次のとおりです。

- `user` が必須です。
- レスポンスの `source_url` は署名付きのダウンロード URL です。
- `user` フィールドより前に届いたすべてのパートの合計サイズは、100 MiB が上限です。
- エラーコードが異なります。



## OpenAPI

````yaml /ja/3.13.x/develop/api/openapi_service.json post /v2/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: データソースプラグインとパイプライン実行を含むナレッジパイプラインの管理と実行のための操作です。
  - name: デプロイ環境
    description: >-
      デプロイ環境が `v2` ベース URL
      で提供するエンドポイントです。デプロイ環境が提供するのはこのグループのエンドポイントだけで、それ以外のパスを呼び出すと `404
      not_found` が返ります。認証とエラーは標準の Service API
      とは異なります。デプロイ環境については、このグループの各ページが正式な情報源です。
paths:
  /v2/files/upload:
    post:
      tags:
        - デプロイ環境
      summary: ファイルをアップロード
      description: >-
        **対象アプリ**：Workflow、Chatflow。


        この環境のこのアプリへのリクエストで使うファイルをアップロードします。


        返される `id` が使えるのは、同じ `user` を持ち、同じアプリと環境に対するリクエストだけです。1 回の実行が参照できるファイルは最大
        100 個です。


        **標準 API
        の対応する操作**：[ファイルをアップロード](/ja/3.13.x/develop/api/files/upload-file)。相違点は次のとおりです。


        - `user` が必須です。

        - レスポンスの `source_url` は署名付きのダウンロード URL です。

        - `user` フィールドより前に届いたすべてのパートの合計サイズは、100 MiB が上限です。

        - エラーコードが異なります。
      operationId: uploadDeployedFileJa
      requestBody:
        description: ファイルアップロードリクエスト。multipart/form-data 形式が必要です。
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
                - user
              properties:
                file:
                  type: string
                  format: binary
                  description: >-
                    アップロードするファイル。`multipart/form-data` の 1 パートとして送信します。ファイル名に
                    `/` や `\` は使えません。


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


                    サイズ上限のデフォルト値はカテゴリごとに、画像 5 MB、音声 50 MB、動画 100 MB、その他のファイル 15
                    MB です。Docker Compose でデプロイした場合、画像の上限は 10 MB
                    です。これらの上限は、プラットフォームの管理者が `UPLOAD_*_FILE_SIZE_LIMIT`
                    [環境変数](/ja/3.13.x/deploy/advanced-configuration/environment-variables)
                    で変更できます。
                user:
                  type: string
                  description: >-
                    エンドユーザーの識別子。アプリ側で定義し、アプリ内で一意にします。ファイルは、このアプリとこの環境における `user`
                    に属します。このパートは `file` より前に送信することを推奨します。それより前に届いたパートの合計サイズは 100
                    MiB
                    が上限です。[エンドユーザーの識別](/ja/3.13.x/develop/api/guides/end-user-identity)
                    を参照してください。
                  maxLength: 512
      responses:
        '201':
          description: 保存されたファイルです。`id` は実行時の参照に使います。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileUploadResponse'
              examples:
                uploadSuccess:
                  summary: レスポンス例
                  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://api.example.com/files/appdeploy/a1b2c3d4-5678-90ab-cdef-1234567890ab/content?token=eyJhbGciOiJIUzI1NiJ9.example
                    original_url: null
                    user_id: null
                    tenant_id: 11223344-5566-7788-99aa-bbccddeeff00
                    conversation_id: null
                    file_key: null
        '400':
          description: >-
            - `invalid_param`：`user` フォームフィールドがありません。`message` は `user form
            field is required` です。

            - `invalid_param`：マルチパートフォームを読み取れません。`message` は `invalid multipart
            form` です。

            - `invalid_param`：`user` が 512 バイトを超えています。`message` は `invalid
            multipart form` です。

            - `invalid_param`：`user` が空、または空白だけです。`message` は `user is invalid`
            です。

            - `invalid_param`：ファイル名に `/` や `\` が含まれます。`message` は `Filename
            contains invalid characters` です。

            - `file_extension_blocked`：ファイルの拡張子が、デプロイのブロックリストに含まれています。

            - `no_file_uploaded`：`file` パートがありません。

            - `too_many_files`：`file` パートが複数送信されました。

            - `filename_not_exists_error`：`file` パートにファイル名がありません。
          content:
            application/json:
              examples:
                invalid_param:
                  summary: invalid_param
                  value:
                    code: invalid_param
                    message: user form field is required
                    status: 400
                invalid_param_multipart:
                  summary: invalid_param（マルチパートフォーム）
                  value:
                    code: invalid_param
                    message: invalid multipart form
                    status: 400
                invalid_param_user:
                  summary: invalid_param（user）
                  value:
                    code: invalid_param
                    message: user is invalid
                    status: 400
                invalid_param_filename:
                  summary: invalid_param（ファイル名）
                  value:
                    code: invalid_param
                    message: Filename contains invalid characters
                    status: 400
                file_extension_blocked:
                  summary: file_extension_blocked
                  value:
                    code: file_extension_blocked
                    message: File extension '.exe' is not allowed for security reasons
                    status: 400
                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.
        '401':
          description: |-
            - `token_invalid`：API キーがない、形式が不正、または不明です。
            - `unauthorized`：API キーが取り消されています。
          content:
            application/json:
              examples:
                token_invalid:
                  summary: token_invalid
                  value:
                    code: token_invalid
                    message: invalid api token
                    status: 401
                unauthorized:
                  summary: unauthorized
                  value:
                    code: unauthorized
                    message: Access token is invalid
                    status: 401
        '403':
          description: '`forbidden`：**アクセスポイント** で、アプリの API アクセスが無効になっています。'
          content:
            application/json:
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    code: forbidden
                    message: The app's API service has been disabled.
                    status: 403
        '404':
          description: >-
            `file_not_found`：`user`
            をこのアプリのエンドユーザーに対応付けられませんでした。続く場合は管理者に連絡してください。
          content:
            application/json:
              examples:
                file_not_found:
                  summary: file_not_found
                  value:
                    code: file_not_found
                    message: File not found.
                    status: 404
        '413':
          description: |-
            - `file_too_large`：`user` フィールドより前に届いたパートが 100 MiB を超えています。
            - `file_too_large`：ファイルが拡張子ごとのサイズ上限を超えています。メッセージにその上限がバイト単位で入ります。
          content:
            application/json:
              examples:
                file_too_large:
                  summary: file_too_large
                  value:
                    status: 413
                    code: file_too_large
                    message: File size exceeded.
                file_too_large_platform_limit:
                  summary: file_too_large（プラットフォームの上限）
                  value:
                    code: file_too_large
                    message: File size exceeded. The limit is 15728640 bytes.
                    status: 413
        '503':
          description: >-
            -
            `file_grant_unavailable`：ファイルのアップロードが一時的に利用できません。しばらくしてから再試行してください。

            -
            `deployment_undeployed`、`deployment_not_ready`、`apprunner_not_deployed`、`enterprise_unavailable`：環境が現在リクエストを処理できません。各コードは
            [ワークフローを実行](/ja/3.13.x/develop/api/deployed-environments/run-workflow)
            を参照してください。
          content:
            application/json:
              examples:
                file_grant_unavailable:
                  summary: file_grant_unavailable
                  value:
                    code: file_grant_unavailable
                    message: file upload is temporarily unavailable
                    status: 503
                deployment_undeployed:
                  summary: deployment_undeployed
                  value:
                    code: deployment_undeployed
                    message: deployment is not deployed
                    status: 503
                deployment_not_ready:
                  summary: deployment_not_ready
                  value:
                    code: deployment_not_ready
                    message: deployment is in progress
                    status: 503
                apprunner_not_deployed:
                  summary: apprunner_not_deployed
                  value:
                    code: apprunner_not_deployed
                    message: apprunner not deployed for this environment
                    status: 503
                enterprise_unavailable:
                  summary: enterprise_unavailable
                  value:
                    code: enterprise_unavailable
                    message: enterprise routing service unavailable
                    status: 503
      servers:
        - url: https://{deployed_api_base_url}
          description: >-
            すべてのデプロイ環境が共有するベース URL です。標準の Service API アドレスで `/v1` を `/v2`
            に置き換えたものです。
          variables:
            deployed_api_base_url:
              default: api.example.com
              description: >-
                アプリの **アクセスポイント** タブで、いずれかのデプロイ環境の **バックエンドサービス API** カードから完全な
                URL をコピーし、先頭の `https://` と末尾の `/v2` を除いてください。
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.13.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.13.x/develop/api/guides/get-started)）。


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

````