1. When to Use File Inputs

  • Retrieve files from (custom) integrated tools to use them directly in Langdock
  • Upload files to a (custom) integrated tool or external API

2. Adding File Fields to an Action

2. 1 Single‑File Input

Add an input field to the action of type file to allow accessing uploaded files later in the action code. image.png

2.2 Multi‑File Input

For multiple file input, select Allow multiple files. Screenshot 2025-07-22 at 19.30.43.png

3. Reading File Data in Code

Every uploaded or referenced file is delivered in a FileData object:
{
  fileName: "Invoice.pdf",
  mimeType: "application/pdf",
  size: 102400,          // bytes
  base64: "JVBERi0xLjQK...", // binary content, Base64‑encoded
  /* Optional shortcut for plain‑text files */
  text: "Hello world"
}

3.1  Single File

const doc = data.input.document;        // FileData
const buffer = Buffer.from(doc.base64, "base64");
ld.log(`Processing ${doc.fileName} (${doc.size} bytes)…`);

3.2  Multiple Files

for (const file of data.input.attachments) {
  const buf = Buffer.from(file.base64, "base64");
  await process(buf, file.mimeType);
}
Shortcut for text files For small UTF‑8 files you may skip Base64 entirely:
{
  fileName: "notes.txt",
  mimeType: "text/plain",
  text: "Hello world"
}

3.3 Common Patterns

4. Returning Files from actions

Building file output from actions is similar to building native download actions.
{
  fileName: "Report.pdf", 		// Original filename
  mimeType: "application/pdf",	// MIME type
  size: 1024000,				// File size in bytes
  base64: "base64EncodedData",	// Base64 encoded file content
}
FieldRequiredNotes
fileNameInclude extension
mimeTypeAccurate type controls preview icons & parsing
sizeFile size in bytes
text / base64✓*Provide one of them, never both
urlOpens the file in the source app
lastModifiedISO‑8601 or Date
dataRaw API response for debugging

5. Platform Constraints

The following constraints have to be considered when implementing actions handling file uploads or retrieval.
LimitValue
Total file size per action run100 MB
Individual documents (single file)≤ 256 MB*
Individual images≤ 20 MB
Individual spreadsheets≤ 30 MB
Individual audio files≤ 200 MB*
Processing TimeoutAction execution timeout of 2 minutes applies to file processing
*Still bounded by the 100 MB overall cap.
Exceeding a limit throws a validation error before your code runs.
{
  "error": "Total file size (120.0 MB) exceeds the action execution limit of 100.0 MB. Please use smaller files or reduce the number of files."
}

6. Best Practices

  • Stream large files if possible; avoid loading >50 MB into memory.
  • Process files in parallel when generating multiple files.
  • Log progress (ld.log("Processing 3/10 files")) to help debugging.

7. Troubleshooting Checklist

Symptom/ErrorLikely Cause & Fix
“File not found”User forgot to attach a file
Make file input field required
Size‑limit errorFile(s) > 100 MB → request smaller batch
File upload/download failsEnsure content is properly base64 encoded
Check logs for file processing errors
The following snippet illustrates a compact logging block that captures the essential metadata without exposing the file contents:
// Quick debug helper
ld.log({
  fileName: file.fileName,
  mimeType: file.mimeType,
  size: file.size,
  hasText: !!file.text,
});