Directus icon

Directus

Consume Directus API

Overview

The Directus - File: Import File operation in n8n allows you to import a file into your Directus instance by providing a URL from which the file will be downloaded. This is useful for automating the process of adding files (such as images, documents, or other assets) to your Directus-managed media library without manual upload.

Common scenarios:

  • Bulk importing files from external sources (e.g., public image repositories, cloud storage links).
  • Automating asset ingestion as part of a data pipeline.
  • Migrating files from another system into Directus.

Practical example:
You have a list of image URLs and want to add them to your Directus project as managed files, possibly with additional metadata (like title or description).


Properties

Name Type Meaning
URL String The direct link to the file you wish to import into Directus. Required.
Additional Fields Collection Optional extra properties for the file object. Allows setting any Directus file object property via JSON.

Output

  • The output is a json object representing the imported file as returned by the Directus API.
  • Typical fields include:
    • id: Unique identifier of the file in Directus.
    • filename_download: The name of the file as stored.
    • title, description, etc.: Any additional metadata provided.
    • type, filesize, width, height, etc.: File details as detected by Directus.
    • Other standard Directus file object fields.

Example output:

{
  "id": "abc123",
  "filename_download": "example.jpg",
  "title": "Example",
  "type": "image/jpeg",
  "filesize": 102400,
  "width": 800,
  "height": 600,
  ...
}

Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.
  • Network Access: The Directus server must be able to reach the provided file URL.

Troubleshooting

Common issues:

  • Invalid URL: If the URL is incorrect or inaccessible, the import will fail.
  • Authentication errors: Missing or invalid Directus API credentials will result in authorization failures.
  • File size limits: Large files may be rejected if they exceed Directus or server-imposed limits.
  • Malformed JSON in Additional Fields: If the JSON for additional fields is not valid, an error will occur.

Error messages and resolutions:

  • "error": "Request failed with status code 404": The file URL does not exist or is unreachable. Check the URL.
  • "error": "Invalid credentials": Ensure your n8n Directus credentials are correct and have sufficient permissions.
  • "error": "Unexpected token ... in JSON": The JSON in "Additional Fields" is malformed. Validate your JSON syntax.

Links and References

Discussion