directus-serve-cli
v0.0.2
Published
Manage directus files to serve them with directus-extension-serve.
Readme
Directus Serve CLI
Manage directus files to serve them with directus-extension-serve.
API
To check the complete CLI API goto API.
Config
All properties can be passed via a config file. We use cosmiconfig to fetch different config files:
By default, Cosmiconfig will check the current directory for the following:
- a package.json property
- a JSON or YAML, extensionless "rc file"
- an "rc file" with the extensions `.json`, `.yaml`, `.yml`, `.js`, `.ts`, `.mjs`, or `.cjs`
- any of the above two inside a `.config` subdirectoryCommands
Upload
Upload files to a Directus instance:
npx directus-serve-cli upload --directusUrl http://localhost:8055 --src ./dist --uploadFolder <your-folder-id> --directusToken <your-access-token>NOTE: You can provide the
directusTokenas well via.envfile or env variable asDIRECTUS_ACCESS_TOKEN. This is helpful for CI/CD environments.
All cli options can be passed via a config file. For more details, check out the API. Here is an example of a config file:
/* .config/custom-upload-config.js */
{
"directusUrl": "http://localhost:8055",
"src": "./dist",
"uploadFolder": "<your-folder-id>"
}npx directus-serve-cli upload --config .config/custom-upload-config.jsDirectus token with upload policy
To upload files to Directus, you need to create a directusToken with the correct upload policy. This token should have permissions to upload files to the specified folder.
First you should create a new policy in Directus that allows uploading files. You can do this by navigating to the Directus admin panel, going to the "Settings" section, and creating a new policy with the necessary permissions:

You can just use All permissions for the upload policy, but you need at least the following permissions:
- id
- title
- folder
- tags
- location
- filename_download
- type
- storage
After creating the policy, you can create a new user, apply the policy to that user, and generate a new access token for that user.

