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

# File Uploads

> Generate and upload files (PDFs, images, videos) from workflows and return them as output to users

## Overview

Workflows can generate files and upload them to Codika's storage using the Codika Upload File node. The uploaded file gets a `documentId` that can be included in the workflow's output as a `file` type field.

## Pattern

```
Generate/Download File → Codika Upload File → Code Node (extract documentId) → Codika Submit Result
```

## Step 1: Generate or download the file

Use any n8n node that produces binary data:

```json theme={null}
{
  "type": "n8n-nodes-base.httpRequest",
  "parameters": {
    "url": "https://api.example.com/generate-pdf",
    "responseFormat": "file"
  },
  "name": "Generate PDF"
}
```

## Step 2: Upload with Codika Upload File

```json theme={null}
{
  "type": "n8n-nodes-codika.codika",
  "typeVersion": 1,
  "parameters": {
    "resource": "fileManagement",
    "operation": "uploadFile"
  },
  "name": "Upload File"
}
```

The node uploads the binary data from the previous node and returns a `documentId`.

## Step 3: Return the documentId in output

In a Code node before Codika Submit Result:

```javascript theme={null}
const documentId = $('Upload File').first().json.documentId;

return [{
  json: {
    results: {
      generated_report: documentId,
      summary: 'Report generated successfully',
    }
  }
}];
```

## Step 4: Define file type in output schema

In `config.ts`:

```typescript theme={null}
function getOutputSchema(): FormOutputSchema {
  return [
    {
      key: 'generated_report',
      type: 'file',
      label: 'Generated Report',
      description: 'PDF report generated by the workflow',
    },
    {
      key: 'summary',
      type: 'string',
      label: 'Summary',
      description: 'Brief summary of the report',
    },
  ];
}
```

## File uploads in sub-workflows

Sub-workflows do not have their own Codika Init node, so the Upload File node needs explicit execution metadata. The parent must forward `executionId` and `executionSecret`.

### Parent workflow passes metadata

```json theme={null}
{
  "type": "n8n-nodes-base.executeWorkflow",
  "parameters": {
    "workflowId": {
      "__rl": true,
      "mode": "id",
      "value": "{{SUBWKFL_pdf-generator_LFKWBUS}}"
    },
    "workflowInputs": {
      "mappingMode": "defineBelow",
      "value": {
        "markdownContent": "={{ $json.markdown }}",
        "fileName": "report.pdf",
        "executionId": "={{ $('Codika Init').first().json.executionId }}",
        "executionSecret": "={{ $('Codika Init').first().json.executionSecret }}"
      }
    }
  }
}
```

### Sub-workflow uses overrides

```json theme={null}
{
  "type": "n8n-nodes-codika.codika",
  "parameters": {
    "resource": "fileManagement",
    "operation": "uploadFile",
    "executionIdOverride": "={{ $('When Called by Parent').first().json.executionId }}",
    "executionSecretOverride": "={{ $('When Called by Parent').first().json.executionSecret }}"
  },
  "name": "Upload File"
}
```

### Sub-workflow input schema in config.ts

```typescript theme={null}
{
  type: 'subworkflow' as const,
  inputSchema: [
    { key: 'markdownContent', type: 'string' },
    { key: 'fileName', type: 'string' },
    { key: 'executionId', type: 'string' },
    { key: 'executionSecret', type: 'string' },
  ],
  calledBy: ['main-workflow'],
}
```

## File input (user uploads)

Users can upload files via the input schema:

```typescript theme={null}
{
  key: 'document',
  type: 'file',
  label: 'Upload Document',
  required: true,
  maxSize: 50 * 1024 * 1024,
  allowedMimeTypes: ['application/pdf', '.docx', '.doc', '.txt'],
}
```

The file data arrives in the webhook payload and can be accessed in workflow nodes.

## Supported file types for upload

The Codika Upload File node supports:

| Category  | Types                                         |
| --------- | --------------------------------------------- |
| Documents | PDF, Word (.docx), Excel (.xlsx), Text (.txt) |
| Images    | PNG, JPG, GIF, SVG, WEBP                      |
| Archives  | ZIP, TAR, TAR.GZ                              |
| Media     | Video (various formats)                       |
| Data      | JSON, YAML, CSV                               |
