From 6582f06a212338125016ade2443cc80447d0a118 Mon Sep 17 00:00:00 2001 From: Mendon Kissling <59585235+mendonk@users.noreply.github.com> Date: Fri, 30 May 2025 13:16:24 -0400 Subject: [PATCH] docs: improve tasks for v2 uploads (#8259) * improve-instructions-for-v2-file-upload * clarify-tweak --- .../api-reference-api-examples.md | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/docs/docs/API-Reference/api-reference-api-examples.md b/docs/docs/API-Reference/api-reference-api-examples.md index eec2804b1..1f369eeee 100644 --- a/docs/docs/API-Reference/api-reference-api-examples.md +++ b/docs/docs/API-Reference/api-reference-api-examples.md @@ -739,8 +739,22 @@ To create a Langflow API key and export it as an environment variable, see [Expo Upload a file to your user account. The file can be used across multiple flows. -The file is uploaded in the format `USER_ID/FILE_ID.FILE_EXTENSION`, such as `6f17a73e-97d7-4519-a8d9-8e4c0be411bb/c7b22c4c-d5e0-4ec9-af97-5d85b7657a34.txt`. -Replace **FILE_NAME.EXTENSION** with the uploaded file name and its extension. +The file is uploaded in the format `USER_ID/FILE_ID.FILE_EXTENSION`, such as `07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf`. + +To retrieve your current `user_id`, call the `/whoami` endpoint. +```bash +curl -X GET \ + "$LANGFLOW_URL/api/v1/users/whoami" \ + -H "accept: application/json" +``` + +Result: +``` +{"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}} +``` + +In the POST request to `v2/files`, replace **@FILE_NAME.EXTENSION** with the uploaded file name and its extension. +You must include the ampersand (`@`) in the request to instruct curl to upload the contents of the file, not the string `FILE_NAME.EXTENSION`. @@ -754,16 +768,15 @@ curl -X POST \ -F "file=@FILE_NAME.EXTENSION" ``` - - +The file is uploaded in the format `USER_ID/FILE_ID.FILE_EXTENSION`, and the API returns metadata about the uploaded file: ```json { - "id": "c7b22c4c-d5e0-4ec9-af97-5d85b7657a34", - "name": "FILE_NAME.EXTENSION", - "path": "6f17a73e-97d7-4519-a8d9-8e4c0be411bb/c7b22c4c-d5e0-4ec9-af97-5d85b7657a34.txt", - "size": 1234, - "provider": null + "id":"d44dc2e1-9ae9-4cf6-9114-8d34a6126c94", + "name":"engine_manual", + "path":"07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf", + "size":851160, + "provider":null } ``` @@ -772,55 +785,65 @@ curl -X POST \ ### Send files to your flows (v2) -Send a file to your flow for analysis using the [File](/components-data#file) component. +Send a file to your flow for analysis using the [File](/components-data#file) component and the API. +Your flow must contain a [File](/components-data#file) component to receive the file. The default file limit is 100 MB. To configure this value, change the `LANGFLOW_MAX_FILE_SIZE_UPLOAD` environment variable. For more information, see [Supported environment variables](/environment-variables#supported-variables). 1. To send an image to your flow with the API, POST the image file to the `/api/v2/files` endpoint. Replace **FILE_NAME** with the uploaded file name. + This is the same step described in [Upload file (v2)](#upload-file-v2), but since you need the filename to upload to your flow, it is included here. ```bash -curl -X POST "$LANGFLOW_URL/api/v2/files" \ +curl -X POST \ + "$LANGFLOW_URL/api/v2/files" \ + -H "accept: application/json" \ -H "Content-Type: multipart/form-data" \ -H "x-api-key: $LANGFLOW_API_KEY" \ - -F "file=@FILE_NAME.png" + -F "file=@FILE_NAME.EXTENSION" ``` The file is uploaded in the format `USER_ID/FILE_ID.FILE_EXTENSION`, and the API returns metadata about the uploaded file: ```json { - "id": "5f829bc4-ac1e-4a80-b1d1-fedc03cd5b6e", - "name": "FILE_NAME", - "path": "232f54ba-dd54-4760-977e-ed637f83e785/5f829bc4-ac1e-4a80-b1d1-fedc03cd5b6e.png", - "size": 84408, + "id":"d44dc2e1-9ae9-4cf6-9114-8d34a6126c94", + "name":"engine_manual", + "path":"07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf", + "size":851160, "provider": null } ``` 2. To use this file in your flow, add a [File](/components-data#file) component to load a file into the flow. 3. To load the file into your flow, send it to the **File** component. +To retrieve the **File** component's full name with the UUID attached, call the [Read flow](#read-flow) endpoint, and then include your **File** component and the file path as a tweak with the `/v1/run` POST request. +In this example, the file uploaded to `/v2/files` is included with the `/v1/run` POST request. ```text curl --request POST \ - --url '$LANGFLOW_URL/api/v1/run/$FLOW_ID' \ - --header 'Content-Type: application/json' \ - --header 'x-api-key: $LANGFLOW_API_KEY' \ + --url "$LANGFLOW_URL/api/v1/run/$FLOW_ID" \ + --header "Content-Type: application/json" \ --data '{ "input_value": "what do you see?", "output_type": "chat", "input_type": "text", "tweaks": { - "File-t2Ngc": { + "File-1olS3": { "path": [ - "232f54ba-dd54-4760-977e-ed637f83e785/5f829bc4-ac1e-4a80-b1d1-fedc03cd5b6e.png" + "07e5b864-e367-4f52-b647-a48035ae7e5e/3a290013-fe1e-4d3d-a454-cacae81288f3.pdf" ] } } }' ``` +Result: +```text +"text":"This document provides important safety information and instructions for selecting, installing, and operating Briggs & Stratton engines. It includes warnings and guidelines to prevent injury, fire, or damage, such as choosing the correct engine model, proper installation procedures, safe fuel handling, and correct engine operation. The document emphasizes following all safety precautions and using authorized parts to ensure safe and effective engine use." +``` + ### List files (v2) List all files associated with your user account.