Back to Langflow

Files endpoints

docs/versioned_docs/version-1.9.0/API-Reference/api-files.mdx

1.10.0.dev2021.5 KB
Original Source

import CodeSnippet from '@site/src/components/CodeSnippet'; import exampleApiFilesUploadFileV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/upload-file-v1.sh'; import resultApiFilesResultUploadFileV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-upload-file-v1.json'; import exampleApiFilesUploadImageFilesV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/upload-image-files-v1.sh'; import exampleApiFilesUploadImageFilesV12 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/upload-image-files-v1-2.sh'; import exampleApiFilesListFilesV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/list-files-v1.sh'; import resultApiFilesResultListFilesV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-list-files-v1.json'; import exampleApiFilesDownloadFileV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/download-file-v1.sh'; import resultApiFilesResultDownloadFileV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-download-file-v1.txt'; import exampleApiFilesDeleteFileV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/delete-file-v1.sh'; import resultApiFilesResultDeleteFileV1 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-delete-file-v1.json'; import exampleApiFilesUploadFileV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/upload-file-v2.sh'; import resultApiFilesResultUploadFileV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-upload-file-v2.txt'; import exampleApiFilesUploadFileV22 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/upload-file-v2-2.sh'; import exampleApiFilesSendFilesToYourFlowsV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/send-files-to-your-flows-v2.sh'; import exampleApiFilesSendFilesToYourFlowsV22 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/send-files-to-your-flows-v2-2.sh'; import exampleApiFilesListFilesV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/list-files-v2.sh'; import resultApiFilesResultListFilesV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-list-files-v2.json'; import exampleApiFilesDownloadFileV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/download-file-v2.sh'; import resultApiFilesResultDownloadFileV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-download-file-v2.txt'; import exampleApiFilesEditFileNameV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/edit-file-name-v2.sh'; import resultApiFilesResultEditFileNameV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-edit-file-name-v2.json'; import exampleApiFilesDeleteFileV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/delete-file-v2.sh'; import resultApiFilesResultDeleteFileV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-delete-file-v2.json'; import exampleApiFilesDeleteAllFilesV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/delete-all-files-v2.sh'; import resultApiFilesResultDeleteAllFilesV2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-files/result-delete-all-files-v2.json'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import examplePythonApiFilesUploadFileV1 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/upload-file-v1.py'; import exampleJavascriptApiFilesUploadFileV1 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/upload-file-v1.js'; import examplePythonApiFilesUploadImageFilesV1 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/upload-image-files-v1.py'; import exampleJavascriptApiFilesUploadImageFilesV1 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/upload-image-files-v1.js'; import examplePythonApiFilesUploadImageFilesV12 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/upload-image-files-v1-2.py'; import exampleJavascriptApiFilesUploadImageFilesV12 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/upload-image-files-v1-2.js'; import examplePythonApiFilesListFilesV1 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/list-files-v1.py'; import exampleJavascriptApiFilesListFilesV1 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/list-files-v1.js'; import examplePythonApiFilesDownloadFileV1 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/download-file-v1.py'; import exampleJavascriptApiFilesDownloadFileV1 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/download-file-v1.js'; import examplePythonApiFilesDeleteFileV1 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/delete-file-v1.py'; import exampleJavascriptApiFilesDeleteFileV1 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/delete-file-v1.js'; import examplePythonApiFilesUploadFileV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/upload-file-v2.py'; import exampleJavascriptApiFilesUploadFileV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/upload-file-v2.js'; import examplePythonApiFilesUploadFileV22 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/upload-file-v2-2.py'; import exampleJavascriptApiFilesUploadFileV22 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/upload-file-v2-2.js'; import examplePythonApiFilesSendFilesToYourFlowsV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/send-files-to-your-flows-v2.py'; import exampleJavascriptApiFilesSendFilesToYourFlowsV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/send-files-to-your-flows-v2.js'; import examplePythonApiFilesSendFilesToYourFlowsV22 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/send-files-to-your-flows-v2-2.py'; import exampleJavascriptApiFilesSendFilesToYourFlowsV22 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/send-files-to-your-flows-v2-2.js'; import examplePythonApiFilesListFilesV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/list-files-v2.py'; import exampleJavascriptApiFilesListFilesV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/list-files-v2.js'; import examplePythonApiFilesDownloadFileV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/download-file-v2.py'; import exampleJavascriptApiFilesDownloadFileV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/download-file-v2.js'; import examplePythonApiFilesEditFileNameV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/edit-file-name-v2.py'; import exampleJavascriptApiFilesEditFileNameV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/edit-file-name-v2.js'; import examplePythonApiFilesDeleteFileV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/delete-file-v2.py'; import exampleJavascriptApiFilesDeleteFileV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/delete-file-v2.js'; import examplePythonApiFilesDeleteAllFilesV2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-files/delete-all-files-v2.py'; import exampleJavascriptApiFilesDeleteAllFilesV2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-files/delete-all-files-v2.js';

Use the /files endpoints to move files between your local machine and Langflow.

All /files endpoints (both /v1/files and /v2/files) require authentication with a Langflow API key. You can only access files that belong to your own user account, even as a superuser.

Differences between /v1/files and /v2/files

There are two versions of the /files endpoints.

/v2/files offers the following improvements over /v1/files:

  • /v2 files are organized by user_id instead of flow_id. This means files are owned by users, and they aren't attached to specific flows. You can upload a file to Langflow one time, and use it with multiple flows.
  • /v2 files are tracked in the Langflow database.
  • /v2 supports bulk upload and delete.
  • /v2 responses contain more descriptive metadata.

However, /v2/files doesn't support image files. To send image files to your flows through the API, use Upload image files (v1).

Files/V1 endpoints

Use the /files endpoints to move files between your local machine and Langflow.

Upload file (v1)

Upload a file to the v1/files/upload/$FLOW_ID endpoint: Replace FILE_NAME with the uploaded file name.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesUploadFileV1} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesUploadFileV1} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesUploadFileV1} language="bash" /> </TabItem> </Tabs>

Replace FILE_NAME.txt with the name and extension of the file you want to upload. Not all file types are supported.

<details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultUploadFileV1} language="json" /> </details>

Upload image files (v1)

Send image files to Langflow to use them in flows.

The default file limit is 1024 MB. To change this limit, set the LANGFLOW_MAX_FILE_SIZE_UPLOAD environment variable.

  1. Attach the image to a POST /v1/files/upload/$FLOW_ID request with --form (-F) and the file path:

    <Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesUploadImageFilesV1} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesUploadImageFilesV1} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesUploadImageFilesV1} language="bash" /> </TabItem> </Tabs>

    A successful request returns the file_path for the image in the Langflow file management system in the format FLOW_ID/TIMESTAMP_FILENAME.TYPE. For example:

    json
    {
      "flowId": "a430cc57-06bb-4c11-be39-d3d4de68d2c4",
      "file_path": "a430cc57-06bb-4c11-be39-d3d4de68d2c4/2024-11-27_14-47-50_image-file.png"
    }
    
  2. Use the returned file_path to send the image file to other components that can accept file input. Where you specify the file path depends on the component type.

    The following example runs the Basic Prompting template flow, passing the image file and the query describe this image as input for the Chat Input component. In this case, the file path is specified in tweaks.

    <Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesUploadImageFilesV12} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesUploadImageFilesV12} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesUploadImageFilesV12} language="bash" /> </TabItem> </Tabs>

    :::tip For help with tweaks, use the Input Schema in a flow's API access pane. Setting tweaks with Input Schema also automatically populates the required component IDs. :::

List files (v1)

List all files associated with a specific flow.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesListFilesV1} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesListFilesV1} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesListFilesV1} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultListFilesV1} language="json" /> </details>

Download file (v1)

Download a specific file from a flow.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesDownloadFileV1} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesDownloadFileV1} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesDownloadFileV1} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultDownloadFileV1} language="text" /> </details>

Delete file (v1)

Delete a specific file from a flow.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesDeleteFileV1} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesDeleteFileV1} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesDeleteFileV1} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultDeleteFileV1} language="json" /> </details>

Files/V2 endpoints

Use the /files endpoints to move files between your local machine and Langflow.

The /v2/files endpoints can be authenticated by an API key or JWT. To create a Langflow API key and export it as an environment variable, see Get started with the Langflow API.

Upload file (v2)

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 07e5b864-e367-4f52-b647-a48035ae7e5e/d44dc2e1-9ae9-4cf6-9114-8d34a6126c94.pdf.

  1. To retrieve your current user_id, call the /whoami endpoint:

    <Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesUploadFileV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesUploadFileV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesUploadFileV2} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultUploadFileV2} language="text" /> </details>
  2. 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.

    <Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesUploadFileV22} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesUploadFileV22} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesUploadFileV22} language="bash" /> </TabItem> </Tabs>

    The file is uploaded in the format USER_ID/FILE_ID.FILE_EXTENSION, and the API returns metadata about the uploaded file:

    json
    {
      "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
    }
    

Send files to your flows (v2)

:::info The /v2/files endpoint can't send image files to flows. To send image files to your flows through the API, see Upload image files (v1). :::

This endpoint uploads files to your Langflow server's file management system. To use an uploaded file in a flow, send the file path to a flow with a Read File component.

The default file limit is 1024 MB. To configure this value, change the LANGFLOW_MAX_FILE_SIZE_UPLOAD environment variable.

  1. To send a file to your flow with the API, POST the file to the /api/v2/files endpoint.

    Replace FILE_NAME.EXTENSION with the name and extension of the file you want to upload. This is the same step described in Upload file (v2), but since you need the filename to upload to your flow, it is included here.

    <Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesSendFilesToYourFlowsV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesSendFilesToYourFlowsV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesSendFilesToYourFlowsV2} language="bash" /> </TabItem> </Tabs>

    The file is uploaded in the format USER_ID/FILE_ID.FILE_EXTENSION, and the API returns metadata about the uploaded file:

    json
    {
      "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 Read File component to your flow. This component loads files into flows from your local machine or Langflow file management.

  3. Run the flow, passing the path to the Read-File component in the tweaks object:

    <Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesSendFilesToYourFlowsV22} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesSendFilesToYourFlowsV22} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesSendFilesToYourFlowsV22} language="bash" /> </TabItem> </Tabs>

    To get the Read-File component's ID, call the Read flow endpoint or inspect the component in the visual editor.

    If the file path is valid, the flow runs successfully.

List files (v2)

List all files associated with your user account.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesListFilesV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesListFilesV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesListFilesV2} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultListFilesV2} language="json" /> </details>

Download file (v2)

Download a specific file by its ID and file extension.

You must specify the file type you expect in the --output value.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesDownloadFileV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesDownloadFileV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesDownloadFileV2} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultDownloadFileV2} language="text" /> </details>

Edit file name (v2)

Change a file name.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesEditFileNameV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesEditFileNameV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesEditFileNameV2} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultEditFileNameV2} language="json" /> </details>

Delete file (v2)

Delete a specific file by its ID.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesDeleteFileV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesDeleteFileV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesDeleteFileV2} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultDeleteFileV2} language="json" /> </details>

Delete all files (v2)

Delete all files associated with your user account.

<Tabs> <TabItem value="Python" label="Python" default> <CodeSnippet source={examplePythonApiFilesDeleteAllFilesV2} language="python" /> </TabItem> <TabItem value="JavaScript" label="JavaScript"> <CodeSnippet source={exampleJavascriptApiFilesDeleteAllFilesV2} language="javascript" /> </TabItem> <TabItem value="curl" label="curl"> <CodeSnippet source={exampleApiFilesDeleteAllFilesV2} language="bash" /> </TabItem> </Tabs> <details> <summary>Result</summary> <CodeSnippet source={resultApiFilesResultDeleteAllFilesV2} language="json" /> </details>

Create upload file (Deprecated)

This endpoint is deprecated. Use the /files endpoints instead.

See also