QR Code

Langflow File Upload Utility

Examples of how to upload files to Langflow

File Only Upload

Uses Langflow File API v2

This component focuses purely on file selection and upload functionality. It provides a clean interface for choosing files with drag-and-drop support and file type validation.

File Component (Process File Only, No LLM/Agent)

File Upload API Endpoint:
http://127.0.0.1:7860/api/v2/files/
Langflow Run API Endpoint:
http://127.0.0.1:7860/api/v1/run/<flowId>
Payload:
{
  "input_value": "Analyze this file",
  "output_type": "chat",
  "input_type": "text"
}

Example Code

# Python example using requests
import requests
import json

# 1. Set the upload URL
url = "http://127.0.0.1:7860/api/v2/files/"

# 2. Prepare the file and payload
payload = {}
files = [
  ('file', ('yourfile.txt', open('yourfile.txt', 'rb'), 'application/octet-stream'))
]
headers = {
  'Accept': 'application/json'
}

# 3. Upload the file to Langflow
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)

# 4. Get the uploaded file path from the response
uploaded_data = response.json()
uploaded_path = uploaded_data.get('path')

# 5. Call the Langflow run endpoint with the uploaded file path
run_url = "http://127.0.0.1:7860/api/v1/run/<flowId>"
run_payload = {
    "input_value": "Analyze this file",
    "output_type": "chat",
    "input_type": "text",
    "tweaks": {
        "File-Component-Name": {
            "path": uploaded_path
        }
    }
}
run_headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
}
run_response = requests.post(run_url, headers=run_headers, data=json.dumps(run_payload))
langflow_data = run_response.json()
# Output only the message
message = None
try:
    message = langflow_data['outputs'][0]['outputs'][0]['results']['message']['data']['text']
except (KeyError, IndexError, TypeError):
    pass
print(message)