directus-module-export
v2.1.0
Published
Directus module for importing and exporting collection data between servers
Maintainers
Readme
Directus Module Export
A Directus module extension for importing collection data from another Directus instance. Simplified for latest Directus versions.
Features ✨
- Directus-to-Directus import 🔁: Transfer collection data from another Directus instance into your current project
- Preflight permission check ✅: Test collection access before importing
- Token validation 🛡️: Validate admin token against the source server
- History management 🕘: Save and reuse domain and token inputs (localStorage)
- Real-time status 📊: Inline progress and concise error messages
- Per-collection import 🧩: Import items for a specific collection
- Import limit option ⏱️: Optionally limit how many items to import per run
- File field support 🖼️: Automatically copies single-file fields (by UUID or object) and reuses or uploads as needed
- ID-preserving import 🔐: Attempts to update items by the same
id; if missing, creates with the sameidusing REST upsert to avoid duplicates - ZIP export/import 📦: Export a collection to a ZIP and re-import elsewhere, including
translations.* - Deep translations import 🌍: Imports
translationsvia deep writes withdeep=true - Folder auto-creation 📁: Files are placed in a collection-named folder, created if missing
At a glance
Installation 📦
From npm
npm install directus-module-exportUsage ▶️
Quick start ⚡
- Open the module in your Directus admin interface.
- Enter the source Directus API URL and an admin-access token for that source.
- (Optional) Click “Validate Token” to check the token, or “Test Collections” to quickly verify collection permissions.
- (Optional) Enter a limit to cap the number of items imported per collection.
- For each collection you want to import, click “Import from another Directus”.
- Monitor the import progress and review the status/output. Any failed items will be summarized in the console.
- (Optional) Use the "History" feature to quickly reuse previously entered domains and tokens, or the "Clear History" options to remove them.
Notes:
- Provide the token as plain string (no need to prefix with "Bearer ").
- The module normalizes tokens internally.
File importing 🖼️
- Supported fields:
- Single-file fields referencing Directus files by UUID (string) or object with
id - Array/many-file relations are skipped (logged as
file_copy_skip) - Non-UUID strings are ignored as file IDs (prevents color values like
#FFFFFFbeing treated as file references)
- Single-file fields referencing Directus files by UUID (string) or object with
- Reuse vs copy:
- If a target item already has a file in a field and it matches the source by checksum (preferred) or file size/type, the existing file is reused
- ZIP import avoids uploading the same image when it already exists in Directus files
- When reusing, the file may be patched to set
title(from item title, if present) and move it into the target folder
- Upload behavior:
- Source file metadata fetched from
/files/{id}; binary fetched from/assets/{id} - Files are uploaded to the target via
/fileswithFormData(file, optionaltitle,folder) - Files are placed in a folder named after the collection; the folder is auto-created if missing
- Title source: uses the item's
titleif available, otherwise first non-empty translationtitle - ZIP import infers MIME type from filename to prevent "Binary Data" files
- ZIP import never uploads control files like
items.jsonor any.jsonfiles
- Source file metadata fetched from
- Caching:
- Per-run cache avoids re-uploading the same source file across multiple items
- Per-item cache prevents duplicate uploads within the same item
- Update mapping (idempotent, optional):
- If the
directus_sync_id_mapcollection exists on the target, imports update existing items mapped by sourceid; otherwise new items are created - ZIP import also maintains this mapping to avoid duplicates on re-import
- If the
- Permissions required:
- Source: read
/items/{collection},/files/{id},/assets/{id} - Target: create/update
/items/{collection},/files,/folders, and (optionally) read/writedirectus_sync_id_map
- Source: read
- Error tolerance:
- If a file copy fails, the item import continues and the field is left unchanged; details are logged as
file_copy_error
- If a file copy fails, the item import continues and the field is left unchanged; details are logged as
Configuration ⚙️
Domain settings 🌐
- Recent domains are stored locally for quick reuse.
Authentication 🔐
- Admin token: Required on the source Directus to READ the collections you import.
- Token validation: The module verifies token usability before import.
Security considerations 🔒
- Admin tokens are stored locally in browser storage.
- Token validation ensures proper permissions.
- Clear history options are available for sensitive data.
- Secure API communication is enforced over HTTPS.
- Imported data is not sent to third-party services; all transfers are direct between your browser and the specified Directus instances.
- Only the collections and fields you select are accessed; no other data is read or modified.
- The module does not store or transmit your data outside your environment.
- For best security, use temporary admin tokens and clear history after use.
Development 🧰
Prerequisites
- Node.js >= 16
- Directus Extensions SDK (
@directus/extensions-sdk) - TypeScript
- Directus CLI (for building and linking extensions)
- npm (Node.js package manager)
Setup
# Install dependencies
npm install
# Build for development
npm run build
# Watch for changes
npm run dev
# Link to Directus instance
npm run linkProject Structure
src/
├── index.ts # Module definition
├── module.vue # Main Vue component
├── types.ts # Shared types
├── utils/
│ └── apiHandlers.ts # API logic for import, validation, and sync
└── shims.d.ts # TypeScript declarationBuilding
# Production build
npm run build
# Development build with watch
npm run devConfiguration
No environment variables are required. Install and enable the module in your Directus instance per normal extension flow.
Compatibility
- Directus host: >= 11.0.0 < 16.0.0
@directus/extensions-sdkpeer range: >= 11 < 16
Troubleshooting 🛠️
Common issues
Token validation fails
- Ensure the token is valid and the API URL is reachable over HTTPS.
403 Forbidden on a collection
- On the source Directus, grant the token’s role READ permission on that collection (and any related collections or files).
- On the target Directus, ensure the role can UPDATE/CREATE with explicit
idand that the collection accepts client-provided primary keys.
History not saving
- Check browser storage permissions; clear cache if needed.
License 📝
MIT License - see LICENSE file for details.
Support 💬
For issues and questions:
- Create an issue on GitHub
- Check the documentation
- Review the troubleshooting section
Changelog 📑
See CHANGELOG.md for version history and updates. Notable:
- 1.1.0: Reworked for Directus v11+, import from Directus-only; removed legacy API import and export flows; improved token handling and preflight checks.
Notes
- Export-to-file functionality is not currently included in this module.
