The File Uploads API allows you to create pre-signed URLs that users can use to upload files directly to Cortex without requiring an API key. This eliminates the need to implement authentication proxies for file uploads, making it easier to collect files from end-users securely.

Use Cases

  • Collecting document uploads from users via your application
  • Enabling file uploads in public-facing forms
  • Gathering user-submitted files for processing in workflows

How It Works

  1. Your application requests a pre-signed upload URL from Cortex
  2. Cortex returns the upload URL and a future file ID
  3. Your application shares the upload URL with the end-user
  4. The user uploads their file directly to this URL
  5. The file becomes available in Cortex and can be referenced using the file ID

Creating a Pre-signed URL

import { Cortex } from '@cortex-ai/sdk';

const cortex = new Cortex({
apiKey: process.env.CORTEX_API_KEY,
});

const uploadInfo = await cortex.apps.files.uploads.create();

// Share uploadInfo.upload_url with your users
// Store uploadInfo.future_file_id to reference the file later

The response includes:
  • upload_url: URL where users can upload files
  • future_file_id: ID that will be assigned to the file once uploaded

Uploading to the Pre-signed URL

Once you have the upload URL, you upload files to it:
const formData = new FormData();
formData.append('file', fileObject); // fileObject from input[type="file"]

// Upload the file
await fetch(uploadInfo.upload_url, {
method: 'POST',
body: formData
});

// Upload a file from a URL
await fetch(uploadInfo.upload_url, {
method: 'POST',
body: JSON.stringify({ file_url: 'https://example.com/files/document.pdf' })
});

Using Uploaded Files in Workflows

After a file is uploaded, The uploaded file is now available using the future_file_id and can be referenced wherever the upload URL was created, such as when running a workflow that requires a file input, for example:
import { Cortex } from '@cortex-ai/sdk';

const cortex = new Cortex({
apiKey: process.env.CORTEX_API_KEY,
});

// Run a workflow with the uploaded file
const run = await cortex.apps.workflows.runs.create('YOUR_WORKFLOW_ID', {
input: {
documents: [uploadInfo.future_file_id]
}
});

File Uploads API Reference

Complete API documentation including all available parameters and response fields