Skip to main content

Upload Files to File Upload Connectors

Learn how to programmatically manage files in your File Upload connectors using the Vectorize API.

Before You Start
This guide assumes you've already set up your Vectorize API client and have access to your organization’s API key and ID.

What are File Upload Connectors?​

File Upload connectors allow you to manually upload files for processing by your RAG pipelines. Unlike automated connectors that sync from external sources (like AWS S3 or Google Drive), File Upload connectors give you direct control over which files to process and when.

List Files in a Connector​

Use the Uploads API to list all files currently in your connector.

# Create API instance
uploads_api = v.UploadsApi(api)

# List files
try:
response = uploads_api.get_upload_files_from_connector(organization_id, source_connector_id)
print(f"Found {len(response.files)} files in connector")

for file in response.files:
print(f" πŸ“„ {file.name} ({file.size:,} bytes, Uploaded: {file.last_modified})")
if file.metadata:
print(f" Metadata: {file.metadata}")
print()

# Test execution continues with the same variables
self.test_runner.log_success(
"List connector files",
f"Found {len(response.files)} files",
status_code=200
)

# Store for later use
self.current_files = response.files
return True

except Exception as e:
print(f"Error listing files: {e}")
self.test_runner.log_failure("List connector files", error=e)
# Initialize empty list so cleanup can still work
self.current_files = []
return False # Changed to False to match JS behavior

Upload a File​

Uploading a file to a connector is a two-step process:

  1. Request a pre-signed upload URL from the API
  2. Upload your file to that URL
import urllib3
import os
import json

# Create API instances
uploads_api = v.UploadsApi(api)

# File details
content_type = "application/pdf" # Set appropriate content type

# Optional metadata - all values as strings
metadata = {
"category": "research",
"tags": "machine-learning,2024", # Store as comma-separated string
"processed": "false" # Store boolean as string
}

try:
# Step 1: Get upload URL
start_response = uploads_api.start_file_upload_to_connector(
organization_id,
source_connector_id,
start_file_upload_to_connector_request=v.StartFileUploadToConnectorRequest(
name=file_name,
content_type=content_type,
metadata=json.dumps(metadata) if metadata else None # Convert to JSON string
)
)

# Step 2: Upload file to the URL
http = urllib3.PoolManager()

with open(file_path, "rb") as f:
response = http.request(
"PUT",
start_response.upload_url,
body=f,
headers={
"Content-Type": content_type,
"Content-Length": str(os.path.getsize(file_path))
}
)

if response.status != 200:
print(f"Upload failed: {response.data}")
else:
print(f"Successfully uploaded {file_name}")

except Exception as e:
print(f"Error during upload: {e}")
note

If a file with the same name already exists in the connector, it will be overwritten.

Working with Metadata​

Metadata allows you to attach additional information to your files that will be preserved throughout processing and can be used for filtering and organization in your RAG pipelines.

Metadata Examples​

# Simple key-value pairs
metadata = {
"department": "engineering",
"year": 2024,
"confidential": True
}

# Arrays and nested objects
metadata = {
"authors": ["John Doe", "Jane Smith"],
"project": {
"name": "AI Research",
"phase": "development"
},
"tags": ["ml", "nlp", "research"]
}

Retrieving Files with Metadata​

When you list files, the metadata is included in the response:

response = uploads_api.get_upload_files_from_connector(organization_id, connector_id)
for file in response.files:
if file.metadata and file.metadata.get("department") == "engineering":
print(f"Engineering file: {file.name}")

Was this page helpful?