Bulk importer
/dashboard/bulk-importer
Chevereto Cloud availability
This feature is not available in Chevereto Cloud.
At Dashboard Bulk importer you can mass import images, albums, and users by parsing the contents of a filesystem location. Use it when you need to import an amount of content that would be troublesome to import using the API or the web user interface.
💡 Importing moves the content into the system: database, filesystem and/or external storage. The importer doesn't mirror a directory: it imports each file and then removes it from the importing path. Files that fail to import are moved to ./importing/failed/.
Requirements
- The bulk importer must be enabled with
CHEVERETO_ENABLE_BULK_IMPORTER=1(default). See Environment. When it's disabled, this dashboard section is hidden and the command exits withBulk importer is disabled. - Everything in
./importing/must be writable by the user running the command (www-data), because the files get removed after they're imported. If a path isn't writable, the job gets canceled and the error is logged. - Only files with an enabled file extension are imported.
Importing path isn't storage
Once a folder has been processed it's removed, along with anything else in it: metadata files and files that weren't imported. Don't keep anything in ./importing/ that you don't want to lose.
How to use it
💡 Check the repository at chevereto/demo-importing for an example on how to organize your files to use the bulk importer.
The bulk importer scans the importing/ path at the root of your installation. Each folder in there is an importing job, and the folder name sets the parsing format for the files it contains.
| ./importing/ | Parsing |
|---|---|
| parse-users/ | Top-level folder as username |
| parse-albums/ | Top-level folders as albums |
| no-parse/ | No folder parsing |
To import content:
- Place the content in the folder for the parsing format you need.
- Run the command, or let cron run it for you.
- Follow the progress at
/dashboard/bulk-importer.
Charset
Files and .json metadata must be in UTF-8.
Command
sudo -u www-data php app/bin/cli -C bulk-importerdocker exec -it --user www-data container_name \
app/bin/cli -C bulk-importerThe command keeps processing the jobs with pending work until there's nothing left to import, and then it exits with [OK] No jobs left. Each job is processed in chunks of up to 500 items.
💡 The dashboard shows the exact command for your installation.
Cron entry
The importing command can be scheduled by using cron. For example, to check for new content every minute:
* * * * * www-data php /var/www/html/app/bin/cli -C bulk-importer >/dev/null 2>&1Adjust the path to app/bin/cli and the user to match your system.
Threads
You can speed up the process by running several importing processes at the same time. Each file is locked in the database while it's being imported, so it's handled by one process only. The THREAD_ID environment variable labels each process in the logs.
sudo -u www-data THREAD_ID=1 \
php app/bin/cli -C bulk-importer &
sudo -u www-data THREAD_ID=2 \
php app/bin/cli -C bulk-importer &docker exec -d --user www-data -e THREAD_ID=1 container_name \
app/bin/cli -C bulk-importer
docker exec -d --user www-data -e THREAD_ID=2 container_name \
app/bin/cli -C bulk-importer💡 Pass THREAD_ID after sudo as shown above: sudo resets the environment, so a variable set before it doesn't reach the command.
File locking
You can hold a job by placing an empty .lock file in its folder. For example, ./importing/parse-users/.lock holds the parse-users job.
touch importing/parse-users/.lockWhile the file exists, the command skips the job and sets it to paused. Remove the file to let importing continue. This comes handy when you copy a large dataset and you don't want the importer to start working on an incomplete folder structure.
Dashboard
The dashboard shows a card for each importing job, with:
- The job folder, such as
./importing/parse-users - The number of files, albums, and users imported
- The job status and the last time it was updated (UTC)
- A red warning icon when the job has logged errors
Use the Actions menu on each card to manage the job.
| Action | Description |
|---|---|
| Reset | Sets the job to working, resets its counters, and deletes its logs |
| Pause | Pauses the job |
| Resume | Sets the job back to working |
| Process log | Opens the log of everything the job did |
| Errors | Opens the log of errors for the job |
💡 Pausing from the dashboard is temporary. Each time the command runs, jobs that haven't been updated in the last minute are set back to working. To hold a job, use file locking.
Logs
Each job writes its logs at app/legacy/importer/jobs/<id>/:
| File | Contents | URL |
|---|---|---|
process.txt | Everything the job did | /importer-jobs/<id>/process |
errors.txt | Errors only | /importer-jobs/<id>/errors |
Log URLs are available to administrators only. Each log line includes the thread that wrote it. On Docker, errors are also written to the container's standard error output.
Parsing formats
The bulk importer scans each job folder and creates content following the parsing rules described below.
Top-level folder as username
Top-level folders within parse-users/ are handled as username. Second-level folders are handled as album name, and deeper folders are handled as sub-albums.
./importing/parse-users
└── rodolfo <- username
├── weapons <- album name
│ ├── machine-gun.jpg
│ ├── rocket-launcher.jpg
│ └── vintage <- sub-album
│ └── revolver.jpg
└── logo-alt.pngFor the tree above, the parser will:
- Use user
rodolfo, creating it if it doesn't exist - Create album
weaponsunder userrodolfo - Create album
vintageinside theweaponsalbum - Upload the images in each folder to its album
- Upload
logo-alt.pngtorodolfo(no album)
Images placed directly in parse-users/ (outside any user folder) are imported as guest.
Usernames
- When a user with the folder name already exists, the content is imported to that user and its user metadata gets updated.
- When the folder name isn't a valid username, a new user is created with a cleaned up name: spaces become
_, characters other than letters, numbers, and_are removed, and the name is cut or padded to fit the username length limits. - When the cleaned up name is already taken, a number is appended to it (
name1,name2, and so on).
Imported users are created without a password.
Top-level folders as albums
Top-level folders within parse-albums/ are handled as album name, owned by guest. Deeper folders are handled as sub-albums.
./importing/parse-albums
└── weapons <- album name
├── machine-gun.jpg
├── rocket-launcher.jpg
└── logo-alt.pngFor the tree above, the parser will:
- Create album
weaponsas guest - Upload the images in
weapons/to theweaponsalbum
Images placed directly in parse-albums/ are imported as guest, with no album.
Guest albums
Albums owned by guest require Guest albums to be enabled. Make sure to enable it before using parse-albums/.
No parse
Folders aren't parsed: every image in no-parse/ is imported as guest, with no album. Images in subfolders are imported too, and the folder structure is ignored.
./importing/no-parse
├── machine-gun.jpg
├── rocket-launcher.jpg
└── logo-alt.pngFor the tree above, the parser will:
- Upload the images in
no-parse/as guest.
Albums aren't matched
Users are matched by username, but albums aren't matched against the albums that already exist. While a job is running, each folder is tracked so all its files go to the same album. Once the job completes, that tracking is cleared: if you later import a folder with the same name, a new album gets created.
Statuses
The importing job statuses are defined as follows:
| Status | Description |
|---|---|
| Queued | Job is in the processing queue |
| Working | Job is being parsed |
| Paused | Job is paused, or held by a lock file |
| Canceled | Job aborted by the user, or by a path that isn't writable |
| Completed | Job completed (nothing left to parse) |
💡 A job shows "completed" when there's nothing left to parse, but it gets set back to working the next time the command runs, so new content placed in its folder will be imported.
Metadata
The bulk importer reads metadata from JSON files. Each user, album, and image has its own metadata file.
✅ Metadata must be in UTF-8 format. Don't forget to fix your charset.
| Content | Type | Metadata file |
|---|---|---|
| rodolfo | username | rodolfo/metadata.json |
| rodolfo/weapons | album | rodolfo/weapons/metadata.json |
| rodolfo/weapons/machine-gun.jpg | image | rodolfo/weapons/machine-gun.json |
| rodolfo/weapons/rocket-launcher.jpg | image | rodolfo/weapons/rocket-launcher.json |
| rodolfo/logo-alt.png | image | rodolfo/logo-alt.json |
For images, you can name the metadata file after the full filename (machine-gun.jpg.json) or after the name without extension (machine-gun.json). When both exist, machine-gun.jpg.json is used.
Tree below shows metadata for the table above.
./importing/parse-users
└── rodolfo
├── weapons
│ ├── machine-gun.jpg
│ ├── machine-gun.json
│ ├── rocket-launcher.jpg
│ ├── rocket-launcher.json
│ └── metadata.json
├── logo-alt.png
├── logo-alt.json
└── metadata.jsonNote
Metadata properties are merged into the content being parsed, so you only need to include the properties you want to set. Properties not listed below are ignored. A property with the wrong type, or a file with invalid JSON, is skipped and logged.
Image metadata
Image metadata goes under the imageData key. JSON metadata file below provides a sample metadata for machine-gun.jpg.
{
"imageData": {
"title": "Machine gun",
"description": "Say hello to my little friend!",
"tags": ["guns", "action"],
"nsfw": true,
"category": {
"name": "Guns",
"urlKey": "guns",
"description": "Guns don't kill people, sugar does."
}
}
}| Property | Type | Description |
|---|---|---|
| title | string | Image title |
| description | string | Image description |
| tags | string or array | Tags, as an array or as a comma separated string |
| nsfw | boolean | Flag the image as not safe content |
| categoryId | integer | ID of an existing category |
| category.urlKey | string | Category URL key, used to find the category |
| category.name | string | Category name, used when creating it (defaults to urlKey) |
| category.description | string | Category description, used when creating it |
💡 When category.urlKey doesn't match any category, the category is created. When you provide categoryId, the category object is ignored.
Album metadata
Album metadata goes under the albumData key. JSON metadata file below provides a sample metadata for the weapons/ album.
{
"albumData": {
"title": "Guns",
"description": "Guns should be banned.",
"privacy": {
"type": "password",
"password": "12345"
}
}
}| Property | Type | Description |
|---|---|---|
| title | string | Album name (defaults to the folder name) |
| description | string | Album description |
| privacy.type | string | Album privacy, see the table below |
| privacy.password | string | Album password, required for password privacy |
For album privacy, you can pick from:
| Privacy type | Effect |
|---|---|
| public | Public album (default) |
| private_but_link | Only those with the album link |
| password | Will set the password for accessing the album |
⚠️ The private (owner only) privacy type isn't applied by the importer: albums using it are created as public.
For example, if you need private_but_link the metadata property should look like this:
{
"albumData": {
"privacy": {
"type": "private_but_link"
}
}
}User metadata
User metadata goes under the userData key. JSON metadata file below provides a sample metadata for the rodolfo/ user.
{
"userData": {
"name": "Rodolfo Berrios",
"email": "rodolfo@chevereto.com",
"website": "https://rodolfoberrios.com",
"bio": "I'm the Master of Puppets @chevereto, the alpha-omega. He/Him/They.",
"profileImages": {
"avatar": "rodo-avatar.jpg",
"background": "rodo-bkg.jpg"
},
"networks": {
"facebook": "no!",
"twitter": "no!"
},
"timezone": "America/Santiago",
"language": "es",
"is_private": false
}
}| Property | Type | Description |
|---|---|---|
| name | string | Display name |
| string | Email address | |
| website | string | Website URL |
| bio | string | Profile bio |
| networks.facebook | string | Facebook username |
| networks.twitter | string | Twitter username |
| timezone | string | Timezone, such as America/Santiago |
| language | string | Language code, such as es |
| is_private | boolean | Make the profile private |
| is_manager | boolean | Give the user the manager role |
| is_admin | boolean | Give the user the administrator role |
| profileImages.avatar | string | Avatar filename, located at .assets/ |
| profileImages.background | string | Background filename, located at .assets/ |
💡 The username always comes from the folder name, it can't be set with metadata.
Profile images have to be located in the .assets/ folder inside the user folder. Files in .assets/ aren't imported as images.
./importing/parse-users
└── rodolfo
└── .assets
├── rodo-avatar.jpg
└── rodo-bkg.jpgUser assets
The type of the image assets must be one of the file formats handled by your installation.
