> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withcortex.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# File Uploads

> Learn how to use the File Uploads API to securely collect files from users without authentication.

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

<CodeGroup>
  ```javascript Node.js SDK theme={"system"}
  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

  ```

  ```bash cURL theme={"system"}
  curl -X POST "https://api.withcortex.ai/apps/c/files/uploads" \
    -H "Authorization: Bearer YOUR_CORTEX_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{}'
  ```
</CodeGroup>

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:

<CodeGroup>
  ```javascript Upload Local File theme={"system"}
  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' })
  });

  ```

  ```bash cURL theme={"system"}
  # Upload a local file
  curl -X POST "https://api.withcortex.ai/public/apps/files/uploads/fupl_xxxx" \
    -F "file=@/path/to/local/document.pdf"

  # Or upload from a URL
  curl -X POST "https://api.withcortex.ai/public/apps/files/uploads/fupl_xxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "file_url": "https://example.com/files/document.pdf"
    }'
  ```
</CodeGroup>

## 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:

<CodeGroup>
  ```javascript Node.js SDK theme={"system"}
  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]
  }
  });

  ```

  ```bash cURL theme={"system"}
  curl -X POST "https://api.withcortex.ai/apps/c/workflows/YOUR_WORKFLOW_ID/runs" \
    -H "Authorization: Bearer YOUR_CORTEX_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "input": {
        "documents": ["afile_xxxx"]
      }
    }'
  ```
</CodeGroup>

<Card title="File Uploads API Reference" icon="code" href="/api-reference/endpoints/files/create-a-new-file-upload">
  Complete API documentation including all available parameters and response
  fields
</Card>

{' '}
