Skip to main content

檔案端點

使用 /files 端點在您的本地機器和 AgentBuilder 之間移動檔案。

/v1/files/v2/files 之間的差異

/files 端點有兩個版本。

/v2/files 相對於 /v1/files 提供以下改進:

  • /v2 檔案按 user_id 而不是 flow_id 組織。 這意味著檔案由使用者擁有,它們不會附加到特定FLOW。 您可以將檔案上傳到 AgentBuilder 一次,並在多個FLOW中使用它。
  • /v2 檔案在 AgentBuilder 資料庫中被追蹤。
  • /v2 支援批量上傳和刪除。
  • /v2 回應包含更具描述性的元資料。

但是,/v2/files 不支援圖像檔案。 要通過 API 將圖像檔案發送到您的FLOW,請使用 上傳圖像檔案 (v1)

Files/V1 端點

使用 /files 端點在您的本地機器和 AgentBuilder 之間移動檔案。

上傳檔案 (v1)

將檔案上傳到 v1/files/upload/$FLOW_ID 端點: 將 FILE_NAME 替換為上傳的檔案名稱。


_10
curl -X POST \
_10
"$LANGFLOW_URL/api/v1/files/upload/$FLOW_ID" \
_10
-H "accept: application/json" \
_10
-H "Content-Type: multipart/form-data" \
_10
-H "x-api-key: $LANGFLOW_API_KEY" \
_10
-F "file=@FILE_NAME.txt"

FILE_NAME.txt 替換為您要上傳的檔案的名稱和擴展名。 並非所有檔案類型都受支援。

Result

_10
{
_10
"flowId": "92f9a4c5-cfc8-4656-ae63-1f0881163c28",
_10
"file_path": "92f9a4c5-cfc8-4656-ae63-1f0881163c28/2024-12-30_15-19-43_your_file.txt"
_10
}

上傳圖像檔案 (v1)

將圖像檔案發送到 AgentBuilder 以在FLOW中使用它們。

預設檔案限制為 1024 MB。 要更改此限制,請設定 LANGFLOW_MAX_FILE_SIZE_UPLOAD 環境變數

  1. 使用 --form (-F) 和檔案路徑將圖像附加到 POST /v1/files/upload/$FLOW_ID 請求:


    _10
    curl -X POST "$LANGFLOW_URL/api/v1/files/upload/$FLOW_ID" \
    _10
    -H "Content-Type: multipart/form-data" \
    _10
    -H "x-api-key: $LANGFLOW_API_KEY" \
    _10
    -F "file=@PATH/TO/FILE.png"

    成功請求會以 FLOW_ID/TIMESTAMP_FILENAME.TYPE 格式返回 AgentBuilder 檔案管理系統中圖像的 file_path。 例如:


    _10
    {
    _10
    "flowId": "a430cc57-06bb-4c11-be39-d3d4de68d2c4",
    _10
    "file_path": "a430cc57-06bb-4c11-be39-d3d4de68d2c4/2024-11-27_14-47-50_image-file.png"
    _10
    }

  2. 使用返回的 file_path 將圖像檔案發送到可以接受檔案輸入的其他Components。您指定檔案路徑的位置取決於Components類型。

    以下範例執行 Basic Prompting 範本FLOW,將圖像檔案和查詢 describe this image 作為 Chat Input Components的輸入傳遞。 在這種情況下,檔案路徑在 tweaks 中指定。


    _14
    curl -X POST \
    _14
    "$LANGFLOW_URL/api/v1/run/a430cc57-06bb-4c11-be39-d3d4de68d2c4?stream=false" \
    _14
    -H "Content-Type: application/json" \
    _14
    -H "x-api-key: $LANGFLOW_API_KEY" \
    _14
    -d '{
    _14
    "output_type": "chat",
    _14
    "input_type": "chat",
    _14
    "tweaks": {
    _14
    "ChatInput-b67sL": {
    _14
    "files": "a430cc57-06bb-4c11-be39-d3d4de68d2c4/2024-11-27_14-47-50_image-file.png",
    _14
    "input_value": "describe this image"
    _14
    }
    _14
    }
    _14
    }'

    tip

    有關 tweaks 的幫助,請使用FLOW的 API access 窗格 中的 Input Schema。 使用 Input Schema 設定 tweaks 也會自動填充所需的Components ID。

列出檔案 (v1)

列出與特定FLOW關聯的所有檔案。


_10
curl -X GET \
_10
"$LANGFLOW_URL/api/v1/files/list/$FLOW_ID" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

Result

_10
{
_10
"files": ["2024-12-30_15-19-43_your_file.txt"]
_10
}

下載檔案 (v1)

從FLOW下載特定檔案。


_10
curl -X GET \
_10
"$LANGFLOW_URL/api/v1/files/download/$FLOW_ID/2024-12-30_15-19-43_your_file.txt" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY" \
_10
--output downloaded_file.txt

Result

_10
File contents downloaded to downloaded_file.txt

刪除檔案 (v1)

從FLOW刪除特定檔案。


_10
curl -X DELETE \
_10
"$LANGFLOW_URL/api/v1/files/delete/$FLOW_ID/2024-12-30_15-19-43_your_file.txt" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

Result

_10
{
_10
"message": "File 2024-12-30_15-19-43_your_file.txt deleted successfully"
_10
}

Files/V2 端點

使用 /files 端點在您的本地機器和 AgentBuilder 之間移動檔案。

/v2/files 端點可以通過 API 金鑰或 JWT 進行驗證。 要建立 AgentBuilder API 金鑰並將其匯出為環境變數,請參閱 開始使用 AgentBuilder API

上傳檔案 (v2)

將檔案上傳到您的使用者帳戶。該檔案可以在多個FLOW中使用。

檔案以上傳格式 USER_ID/FILE_ID.FILE_EXTENSION 上傳,例如 07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf

  1. 要檢索您當前的 user_id,呼叫 /whoami 端點:


    _10
    curl -X GET \
    _10
    "$LANGFLOW_URL/api/v1/users/whoami" \
    _10
    -H "accept: application/json" \
    _10
    -H "x-api-key: $LANGFLOW_API_KEY"

    Result

    _10
    {"id":"07e5b864-e367-4f52-b647-a48035ae7e5e","username":"langflow","profile_image":null,"store_api_key":null,"is_active":true,"is_superuser":true,"create_at":"2025-05-08T17:59:07.855965","updated_at":"2025-05-28T19:00:42.556460","last_login_at":"2025-05-28T19:00:42.554338","optins":{"github_starred":false,"dialog_dismissed":true,"discord_clicked":false,"mcp_dialog_dismissed":true}}

  2. 在 POST 請求到 v2/files 中,將 @FILE_NAME.EXTENSION 替換為上傳的檔案名稱及其擴展名。 您必須在請求中包含 and 符號 (@) 以指示 curl 上傳檔案的內容,而不是字串 FILE_NAME.EXTENSION


    _10
    curl -X POST \
    _10
    "$LANGFLOW_URL/api/v2/files" \
    _10
    -H "accept: application/json" \
    _10
    -H "Content-Type: multipart/form-data" \
    _10
    -H "x-api-key: $LANGFLOW_API_KEY" \
    _10
    -F "file=@FILE_NAME.EXTENSION"

    檔案以上傳格式 USER_ID/FILE_ID.FILE_EXTENSION 上傳,API 返回有關上傳檔案的元資料:


    _10
    {
    _10
    "id":"d44dc2e1-9ae9-4cf6-9114-8d34a6126c94",
    _10
    "name":"engine_manual",
    _10
    "path":"07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf",
    _10
    "size":851160,
    _10
    "provider":null
    _10
    }

將檔案發送到您的FLOW (v2)

info

/v2/files 端點無法將圖像檔案發送到FLOW。 要通過 API 將圖像檔案發送到您的FLOW,請參閱 上傳圖像檔案 (v1)

此端點將檔案上傳到您的 AgentBuilder 伺服器的檔案管理系統。 要在FLOW中使用上傳的檔案,請使用 File Components 將檔案路徑發送到FLOW。

預設檔案限制為 1024 MB。要配置此值,請更改 LANGFLOW_MAX_FILE_SIZE_UPLOAD 環境變數

  1. 要使用 API 將檔案發送到您的FLOW,請將檔案 POST 到 /api/v2/files 端點。

    FILE_NAME.EXTENSION 替換為您要上傳的檔案的名稱和擴展名。 這是 上傳檔案 (v2) 中描述的相同步驟,但由於您需要檔案名稱來上傳到您的FLOW,因此在此處包含。


    _10
    curl -X POST \
    _10
    "$LANGFLOW_URL/api/v2/files" \
    _10
    -H "accept: application/json" \
    _10
    -H "Content-Type: multipart/form-data" \
    _10
    -H "x-api-key: $LANGFLOW_API_KEY" \
    _10
    -F "file=@FILE_NAME.EXTENSION"

    檔案以上傳格式 USER_ID/FILE_ID.FILE_EXTENSION 上傳,API 返回有關上傳檔案的元資料:


    _10
    {
    _10
    "id":"d44dc2e1-9ae9-4cf6-9114-8d34a6126c94",
    _10
    "name":"engine_manual",
    _10
    "path":"07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf",
    _10
    "size":851160,
    _10
    "provider": null
    _10
    }

  2. 要在您的FLOW中使用此檔案,請將 File Components新增到您的FLOW。 此Components從您的本地機器或 AgentBuilder 檔案管理將檔案載入到FLOW中。

  3. 執行FLOW,在 tweaks 物件中將 path 傳遞給 File Components:


    _16
    curl --request POST \
    _16
    --url "$LANGFLOW_URL/api/v1/run/$FLOW_ID" \
    _16
    --header "Content-Type: application/json" \
    _16
    --header "x-api-key: $LANGFLOW_API_KEY" \
    _16
    --data '{
    _16
    "input_value": "what do you see?",
    _16
    "output_type": "chat",
    _16
    "input_type": "text",
    _16
    "tweaks": {
    _16
    "File-1olS3": {
    _16
    "path": [
    _16
    "07e5b864-e367-4f52-b647-a48035ae7e5e/3a290013-fe1e-4d3d-a454-cacae81288f3.pdf"
    _16
    ]
    _16
    }
    _16
    }
    _16
    }'

    要獲取 File Components的 ID,請呼叫 Read flow 端點或在視覺編輯器中檢查Components。

    如果檔案路徑有效,FLOW會成功執行。

列出檔案 (v2)

列出與您的使用者帳戶關聯的所有檔案。


_10
curl -X GET \
_10
"$LANGFLOW_URL/api/v2/files" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

Result

_10
[
_10
{
_10
"id": "c7b22c4c-d5e0-4ec9-af97-5d85b7657a34",
_10
"name": "your_file",
_10
"path": "6f17a73e-97d7-4519-a8d9-8e4c0be411bb/c7b22c4c-d5e0-4ec9-af97-5d85b7657a34.txt",
_10
"size": 1234,
_10
"provider": null
_10
}
_10
]

下載檔案 (v2)

按其 ID 和檔案擴展名下載特定檔案。

您必須在 --output 值中指定您期望的檔案類型。


_10
curl -X GET \
_10
"$LANGFLOW_URL/api/v2/files/c7b22c4c-d5e0-4ec9-af97-5d85b7657a34" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY" \
_10
--output downloaded_file.txt

Result

_10
File contents downloaded to downloaded_file.txt

編輯檔案名稱 (v2)

更改檔案名稱。


_10
curl -X PUT \
_10
"$LANGFLOW_URL/api/v2/files/$FILE_ID?name=new_file_name" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

Result

_10
{
_10
"id": "76543e40-f388-4cb3-b0ee-a1e870aca3d3",
_10
"name": "new_file_name",
_10
"path": "6f17a73e-97d7-4519-a8d9-8e4c0be411bb/76543e40-f388-4cb3-b0ee-a1e870aca3d3.png",
_10
"size": 2728251,
_10
"provider": null
_10
}

刪除檔案 (v2)

按其 ID 刪除特定檔案。


_10
curl -X DELETE \
_10
"$LANGFLOW_URL/api/v2/files/$FILE_ID" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

Result

_10
{
_10
"message": "File deleted successfully"
_10
}

刪除所有檔案 (v2)

刪除與您的使用者帳戶關聯的所有檔案。


_10
curl -X DELETE \
_10
"$LANGFLOW_URL/api/v2/files" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

Result

_10
{
_10
"message": "All files deleted successfully"
_10
}

建立上傳檔案 (已棄用)

此端點已棄用。請改用 /files 端點。

另請參閱

Search