Directus icon

Directus

Consume Directus API

Overview

The Directus n8n node's "File" resource with the "Create / Upload" operation allows you to upload new files to a Directus instance. This is useful for automating file management tasks, such as uploading images, documents, or other assets directly from your workflow into your Directus project's file library.

Common scenarios:

  • Automating the upload of user-submitted files (e.g., from forms).
  • Syncing files from external sources (like cloud storage) into Directus.
  • Attaching files to items in collections as part of a data import process.

Practical example:
You could use this node to automatically upload PDF invoices generated earlier in your workflow to Directus, making them available for download or further processing.


Properties

Name Type Meaning
Send Binary Data boolean Determines whether to upload a file using binary data from a previous node. Set to true to upload a file; set to false to create a file record without uploading binary content. Required.
Binary Property string The name of the binary property that contains the file data to be uploaded. For multiple files, provide a comma-separated list of property names. Required when "Send Binary Data" is true.
Additional Fields collection Allows you to specify extra properties for the file object as defined by the Directus file object. Use the "File Object (JSON)" field for custom metadata.
File Object (JSON) json (Within Additional Fields) JSON object containing additional file metadata/properties as accepted by Directus.

Output

  • The output will be a single item with a json field containing the response from Directus after the file is created/uploaded.
  • The structure of the json field typically matches the Directus file object, including fields like id, filename_download, title, type, filesize, url, etc.
  • If the operation fails and "Continue On Fail" is enabled, the output will contain an error field with the error message.

Example output:

{
  "id": "abc123",
  "filename_download": "invoice.pdf",
  "title": "Invoice April",
  "type": "application/pdf",
  "filesize": 102400,
  "url": "/assets/abc123",
  ...
}

Dependencies

  • Directus API: You must have access to a running Directus instance.
  • API Credentials: The node requires valid Directus API credentials (directusApi) configured in n8n.
  • Binary Data: If uploading a file, the binary data must be present in the input under the specified property name.

Troubleshooting

Common issues:

  • Missing Binary Data: If "Send Binary Data" is true but the specified binary property does not exist, the node will throw an error.
  • Invalid JSON: If the "File Object (JSON)" field contains invalid JSON, the request will fail.
  • Authentication Errors: Invalid or missing API credentials will result in authentication errors from Directus.
  • File Size Limits: Uploads may fail if the file exceeds server-side limits set in Directus.

Error messages and resolutions:

  • "Cannot read property 'fileName' of undefined": Check that the binary property name matches the actual property in the input.
  • "Unexpected token ... in JSON": Ensure any JSON fields are properly formatted.
  • "401 Unauthorized": Verify your Directus API credentials in n8n.

Links and References

Discussion