Skip to content

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 with Bulk 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:

  1. Place the content in the folder for the parsing format you need.
  2. Run the command, or let cron run it for you.
  3. Follow the progress at /dashboard/bulk-importer.

Charset ​

Files and .json metadata must be in UTF-8.

Command ​

sh
sudo -u www-data php app/bin/cli -C bulk-importer
sh
docker exec -it --user www-data container_name \
    app/bin/cli -C bulk-importer

The 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:

sh
* * * * * www-data php /var/www/html/app/bin/cli -C bulk-importer >/dev/null 2>&1

Adjust 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.

sh
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 &
sh
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.

sh
touch importing/parse-users/.lock

While 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.

ActionDescription
ResetSets the job to working, resets its counters, and deletes its logs
PausePauses the job
ResumeSets the job back to working
Process logOpens the log of everything the job did
ErrorsOpens 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>/:

FileContentsURL
process.txtEverything the job did/importer-jobs/<id>/process
errors.txtErrors 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.

shell
./importing/parse-users
└── rodolfo <- username
    ├── weapons <- album name
    │   ├── machine-gun.jpg
    │   ├── rocket-launcher.jpg
    │   └── vintage <- sub-album
    │       └── revolver.jpg
    └── logo-alt.png

For the tree above, the parser will:

  • Use user rodolfo, creating it if it doesn't exist
  • Create album weapons under user rodolfo
  • Create album vintage inside the weapons album
  • Upload the images in each folder to its album
  • Upload logo-alt.png to rodolfo (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.

shell
./importing/parse-albums
└── weapons <- album name
    ├── machine-gun.jpg
    ├── rocket-launcher.jpg
    └── logo-alt.png

For the tree above, the parser will:

  • Create album weapons as guest
  • Upload the images in weapons/ to the weapons album

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.

shell
./importing/no-parse
├── machine-gun.jpg
├── rocket-launcher.jpg
└── logo-alt.png

For 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:

StatusDescription
QueuedJob is in the processing queue
WorkingJob is being parsed
PausedJob is paused, or held by a lock file
CanceledJob aborted by the user, or by a path that isn't writable
CompletedJob 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.

ContentTypeMetadata file
rodolfousernamerodolfo/metadata.json
rodolfo/weaponsalbumrodolfo/weapons/metadata.json
rodolfo/weapons/machine-gun.jpgimagerodolfo/weapons/machine-gun.json
rodolfo/weapons/rocket-launcher.jpgimagerodolfo/weapons/rocket-launcher.json
rodolfo/logo-alt.pngimagerodolfo/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.

shell
./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.json

Note

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.

json
{
    "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."
        }
    }
}
PropertyTypeDescription
titlestringImage title
descriptionstringImage description
tagsstring or arrayTags, as an array or as a comma separated string
nsfwbooleanFlag the image as not safe content
categoryIdintegerID of an existing category
category.urlKeystringCategory URL key, used to find the category
category.namestringCategory name, used when creating it (defaults to urlKey)
category.descriptionstringCategory 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.

json
{
    "albumData": {
        "title": "Guns",
        "description": "Guns should be banned.",
        "privacy": {
            "type": "password",
            "password": "12345"
        }
    }
}
PropertyTypeDescription
titlestringAlbum name (defaults to the folder name)
descriptionstringAlbum description
privacy.typestringAlbum privacy, see the table below
privacy.passwordstringAlbum password, required for password privacy

For album privacy, you can pick from:

Privacy typeEffect
publicPublic album (default)
private_but_linkOnly those with the album link
passwordWill 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:

json
{
    "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.

json
{
    "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
    }
}
PropertyTypeDescription
namestringDisplay name
emailstringEmail address
websitestringWebsite URL
biostringProfile bio
networks.facebookstringFacebook username
networks.twitterstringTwitter username
timezonestringTimezone, such as America/Santiago
languagestringLanguage code, such as es
is_privatebooleanMake the profile private
is_managerbooleanGive the user the manager role
is_adminbooleanGive the user the administrator role
profileImages.avatarstringAvatar filename, located at .assets/
profileImages.backgroundstringBackground 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.

shell
./importing/parse-users
└── rodolfo
    └── .assets
        ├── rodo-avatar.jpg
        └── rodo-bkg.jpg

User assets

The type of the image assets must be one of the file formats handled by your installation.

Released under the Apache-2.0 License.