File Uploads¶
The MicroDC platform supports uploading files and creating download tokens for multimodal AI workflows.
Upload a File¶
from microdc import Client
client = Client(api_key="mDC_...")
upload_result = client.upload_file("contract.pdf", description="Legal contract")
print(f"File ID: {upload_result['id']}")
print(f"File size: {upload_result['file_size']} bytes")
The upload response contains:
| Field | Description |
|---|---|
id |
File ID (use as token for DocumentCall) |
original_name |
Original filename |
file_path |
Server-side path |
file_size |
Size in bytes |
Create a Download Token¶
Generate a one-time download URL for an uploaded file:
token_data = client.create_download_token(
file_id=upload_result['id'],
expires_in_minutes=60, # 1-10080 minutes
max_uses=1 # 1-100 uses
)
print(f"Download URL: {token_data['download_url']}")
print(f"Expires at: {token_data['expires_at']}")
Upload and Tokenize (One Step)¶
Combine upload and token creation:
file_token = client.upload_and_tokenize(
"contract.pdf",
description="Legal contract for analysis",
expires_in_minutes=60,
max_uses=1
)
print(f"File ID: {file_token['file_id']}")
print(f"Download URL: {file_token['download_url']}")
Use with Document Processing¶
Files must be uploaded before creating DocumentCall jobs:
from microdc import Client, DocumentCall
client = Client(api_key="mDC_...")
# Upload file
upload_result = client.upload_file("document.pdf")
file_token = upload_result['id']
# Process with docling
job = DocumentCall(model="docling")
job.add_file(file_token)
job_id = client.send_job(job)
client.wait_for_all()
result = client.get_job_details(job_id)
print(result.result)
Use with LLM (Vision/Multimodal)¶
Use download URLs to pass files to LLM models:
from microdc import Client, LLMChat
client = Client(api_key="mDC_...")
# Upload and get download URL
file_token = client.upload_and_tokenize(
"product_photo.jpg",
expires_in_minutes=30
)
# Vision model analysis
chat = LLMChat(model="gpt-4-vision")
chat.input_modalities = ["text", "image"]
chat.output_modalities = ["text"]
chat.set_system("You are a product analyst.")
chat.add_user_message("What product is this?")
job_id = client.send_job(chat)
details = client.wait_for_job(job_id)
print(details.result)
Batch File Upload¶
from microdc import Client, DocumentCall
client = Client(api_key="mDC_...")
files = ["report_q1.pdf", "report_q2.pdf", "report_q3.pdf"]
# Upload all files
tokens = []
for filepath in files:
result = client.upload_file(filepath)
tokens.append(result['id'])
print(f"Uploaded {filepath}")
# Submit processing jobs
job_ids = []
for i, token in enumerate(tokens):
job = DocumentCall(model="docling")
job.add_file(token)
job.metadata = {"filename": files[i]}
job_ids.append(client.send_job(job))
client.wait_for_all(timeout=600)