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

# ファイルからドキュメントを作成

> ファイルをアップロードしてドキュメントを作成します。一般的なドキュメント形式（PDF、TXT、DOCX など）をサポートしています。処理は非同期で行われるため、返された `batch` ID を [ドキュメント埋め込みステータス（進捗）を取得](/ja/api-reference/documents/get-document-indexing-status) で使用して進捗を追跡します。



## OpenAPI

````yaml /ja/api-reference/openapi_service.json post /datasets/{dataset_id}/document/create-by-file
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.dify.ai/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:
  /datasets/{dataset_id}/document/create-by-file:
    post:
      tags:
        - ドキュメント
      summary: ファイルからドキュメントを作成
      description: >-
        ファイルをアップロードしてドキュメントを作成します。一般的なドキュメント形式（PDF、TXT、DOCX
        など）をサポートしています。処理は非同期で行われるため、返された `batch` ID を
        [ドキュメント埋め込みステータス（進捗）を取得](/ja/api-reference/documents/get-document-indexing-status)
        で使用して進捗を追跡します。
      operationId: createDocumentFromFile
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: ナレッジベース ID です。
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: アップロードするファイルです。
                data:
                  type: string
                  description: >-
                    設定情報を含む JSON
                    文字列です。[テキストからドキュメントを作成](/ja/api-reference/documents/create-document-by-text)
                    と同じフィールド（`indexing_technique`、`doc_form`、`doc_language`、`process_rule`、`retrieval_model`、`embedding_model`、`embedding_model_provider`）を受け付けますが、`name`
                    と `text` は除きます。
                  example: >-
                    {"indexing_technique":"high_quality","doc_form":"text_model","doc_language":"English","process_rule":{"mode":"automatic"}}
      responses:
        '200':
          description: ドキュメントが正常に作成されました。
          content:
            application/json:
              schema:
                type: object
                properties:
                  document:
                    $ref: '#/components/schemas/Document'
                  batch:
                    type: string
                    description: インデックス進捗を追跡するためのバッチ ID です。
              examples:
                success:
                  summary: レスポンス例
                  value:
                    document:
                      id: a8e0e5b5-78c6-4130-a5ce-25feb0e0b4ac
                      position: 1
                      data_source_type: upload_file
                      data_source_info:
                        upload_file_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                      data_source_detail_dict:
                        upload_file:
                          id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                          name: guide.txt
                          size: 2048
                          extension: txt
                          mime_type: text/plain
                          created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                          created_at: 1741267200
                      dataset_process_rule_id: e1f2a3b4-c5d6-7890-ef12-345678901234
                      name: guide.txt
                      created_from: api
                      created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                      created_at: 1741267200
                      tokens: 0
                      indexing_status: indexing
                      error: null
                      enabled: true
                      disabled_at: null
                      disabled_by: null
                      archived: false
                      display_status: indexing
                      word_count: 0
                      hit_count: 0
                      doc_form: text_model
                      doc_metadata: []
                      summary_index_status: null
                      need_summary: false
                    batch: '20250306150245647595'
        '400':
          description: >-
            - `no_file_uploaded` : ファイルをアップロードしてください。

            - `too_many_files` : アップロードできるファイルは 1 つだけです。

            - `filename_not_exists_error` : 指定されたファイル名が存在しません。

            - `provider_not_initialize` : 有効なモデルプロバイダーの認証情報が見つかりません。Settings ->
            Model Provider でプロバイダーの認証情報を設定してください。

            - `invalid_param` : 外部ナレッジベースはサポートされていません。`indexing_technique`
            が必須、または `process_rule` がありません。
          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.
                provider_not_initialize:
                  summary: provider_not_initialize
                  value:
                    status: 400
                    code: provider_not_initialize
                    message: >-
                      No valid model provider credentials found. Please go to
                      Settings -> Model Provider to complete your provider
                      credentials.
                invalid_param_external:
                  summary: invalid_param (external)
                  value:
                    status: 400
                    code: invalid_param
                    message: External datasets are not supported.
        '403':
          description: |-
            - `forbidden` : このナレッジベースでは API アクセスが有効になっていません。
            - `forbidden` : ベクトル空間の容量がサブスクリプションの上限に達しました。
            - `forbidden` : ドキュメント数がサブスクリプションの上限に達しました。
            - `forbidden` : サブスクリプションのナレッジベースリクエストのレート制限に達しました。
          content:
            application/json:
              examples:
                forbidden_1:
                  summary: forbidden (api access)
                  value:
                    status: 403
                    code: forbidden
                    message: Dataset api access is not enabled.
                forbidden_2:
                  summary: forbidden (vector space)
                  value:
                    status: 403
                    code: forbidden
                    message: >-
                      The capacity of the vector space has reached the limit of
                      your subscription.
                forbidden_3:
                  summary: forbidden (documents limit)
                  value:
                    status: 403
                    code: forbidden
                    message: >-
                      The number of documents has reached the limit of your
                      subscription.
                forbidden_4:
                  summary: forbidden (rate limit)
                  value:
                    status: 403
                    code: forbidden
                    message: >-
                      Sorry, you have reached the knowledge base request rate
                      limit of your subscription.
        '404':
          description: '`not_found` : ナレッジベースが見つかりません。'
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    status: 404
                    code: not_found
                    message: Dataset not found.
components:
  schemas:
    Document:
      type: object
      properties:
        id:
          type: string
          description: ドキュメントの一意識別子です。
        position:
          type: integer
          description: リスト内のドキュメントの表示位置です。
        data_source_type:
          type: string
          description: >-
            ドキュメントの作成方法です。ファイルアップロードの場合は `upload_file`、Notion インポートの場合は
            `notion_import` です。
        data_source_info:
          type: object
          description: 生のデータソース情報です。`data_source_type` によって異なります。
        data_source_detail_dict:
          type: object
          description: ファイル詳細を含む詳細なデータソース情報です。
        dataset_process_rule_id:
          type: string
          description: このドキュメントに適用された処理ルールの ID です。
        name:
          type: string
          description: ドキュメント名です。
        created_from:
          type: string
          description: ドキュメントの作成元です。API で作成した場合は `api`、UI で作成した場合は `web` です。
        created_by:
          type: string
          description: ドキュメントを作成したユーザーの ID です。
        created_at:
          type: number
          description: 作成タイムスタンプ（Unix エポック、秒単位）です。
        tokens:
          type: integer
          description: ドキュメント内の合計トークン数です。
        indexing_status:
          type: string
          description: >-
            現在のインデックスステータスです。`waiting` はキュー待ち、`parsing` はコンテンツ抽出中、`cleaning`
            はノイズ除去中、`splitting` はチャンキング中、`indexing` はベクトル構築中、`completed`
            は準備完了、`error` は失敗、`paused` は手動一時停止を示します。
        error:
          type: string
          nullable: true
          description: インデックス作成が失敗した場合のエラーメッセージです。エラーなしの場合は `null` です。
        enabled:
          type: boolean
          description: このドキュメントが検索に対して有効かどうかです。
        disabled_at:
          type: number
          nullable: true
          description: ドキュメントが無効化されたタイムスタンプです。有効な場合は `null` です。
        disabled_by:
          type: string
          nullable: true
          description: ドキュメントを無効化したユーザーの ID です。有効な場合は `null` です。
        archived:
          type: boolean
          description: ドキュメントがアーカイブ済みかどうかです。
        display_status:
          type: string
          description: '`indexing_status` と `enabled` 状態から導出されたユーザー向け表示ステータスです。'
        word_count:
          type: integer
          description: ドキュメントの合計単語数です。
        hit_count:
          type: integer
          description: ドキュメントが検索クエリでマッチした回数です。
        doc_form:
          type: string
          description: >-
            ドキュメントのチャンキングモードです。`text_model` は標準テキストチャンキング、`hierarchical_model`
            は親子構造、`qa_model` は QA ペア抽出を示します。
        doc_metadata:
          type: array
          description: このドキュメントに割り当てられたメタデータ値です。
          items:
            type: object
            properties:
              id:
                type: string
                description: メタデータフィールドの識別子です。
              name:
                type: string
                description: メタデータフィールド名です。
              type:
                type: string
                description: メタデータフィールドの値の種類です。
              value:
                type: string
                description: このドキュメントのメタデータ値。
        summary_index_status:
          type: string
          nullable: true
          description: このドキュメントの要約インデックスのステータスです。要約インデックスが設定されていない場合は `null` です。
        need_summary:
          type: boolean
          description: このドキュメントに要約を生成する必要があるかどうかです。
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key 認証です。すべての API リクエストにおいて、`Authorization` HTTP ヘッダーに `Bearer `
        プレフィックスを付けた API Key を含めてください。例：`Authorization: Bearer {API_KEY}`。**API
        Key はサーバーサイドに保存し、クライアントサイドで共有・保存しないことを強く推奨します。API Key
        の漏洩は深刻な結果につながる可能性があります。**API Key が欠落または無効な場合、HTTP `401` とエラーコード
        `unauthorized` が返されます。

````