Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Files → Import File operation in this n8n node allows you to import a file into Directus by providing a URL from which the file will be downloaded. This is useful for automating the process of adding files to your Directus instance without manual upload, especially when files are hosted externally or generated dynamically.

Common scenarios:

  • Automatically importing images, documents, or other assets from external sources (e.g., cloud storage, public URLs) into Directus.
  • Integrating with workflows where files are created elsewhere and need to be registered in Directus for further processing or cataloging.
  • Migrating or syncing files from another system into Directus using their URLs.

Practical example:
You have a list of image URLs from a third-party service and want to batch-import them as files into your Directus CMS for use in your application.


Properties

Name Type Meaning
URL String The URL to download the file from. This is the source location of the file to be imported into Directus.
Additional Fields Collection Optional extra fields to customize the import. Contains:
- File Object (JSON) (json): Any additional properties for the file object as per Directus file object documentation. Used to set metadata such as title, description, tags, etc.

Output

The output will be a single item with a json field containing the response from Directus after importing the file. The structure typically includes details about the newly created file object, such as:

{
  "id": "unique-file-id",
  "filename_download": "original-filename.ext",
  "title": "Example",
  "type": "mime/type",
  "filesize": 12345,
  "url": "/assets/unique-file-id",
  ...
}
  • The exact fields depend on the Directus API and any additional data provided via "File Object (JSON)".
  • No binary data is returned by this operation; only JSON metadata about the imported file.

Dependencies

  • External Service: Requires access to a running Directus instance with API enabled.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.
  • Environment: The Directus instance must be able to reach the provided file URL (i.e., the URL must be publicly accessible or accessible from the server running Directus).

Troubleshooting

Common issues:

  • Invalid or Inaccessible URL: If the URL is incorrect or not reachable from the Directus server, the import will fail. Ensure the URL is correct and accessible.
  • Malformed JSON in Additional Fields: If the "File Object (JSON)" is not valid JSON, the request will fail. Double-check your JSON syntax.
  • Missing Required Fields: The "URL" property is required. Omitting it will result in an error.
  • Authentication Errors: Invalid or missing Directus API credentials will cause authentication failures.

Error messages and resolutions:

  • "error": "Request failed with status code 404": The file could not be found at the specified URL. Check the URL.
  • "error": "Invalid JSON": The "File Object (JSON)" field contains invalid JSON. Validate your input.
  • "error": "Unauthorized": Check your Directus API credentials configuration in n8n.

Links and References

Discussion