After a site has been running for two years, its upload directory often holds hundreds of images: old illustrations nobody removed after an article was rewritten, sample images left behind when a product was taken offline, and duplicate copies of the same image uploaded over and over. Disk space is the lesser problem; the real trouble is not knowing which image is still in use, and a wrong deletion blanks out a page. That is exactly what the X1 Image Management module solves.

Example of a KingCMS X1 admin business page
The Image Management module is disabled by default; once enabled it appears under the “Marketing & SEO” group.

1. Where it is and how to enable it

Go to “System Settings → Modules & Themes → Module Management” and check “Image Management”; “Image Management” then appears under “Marketing & SEO” on the left, at the address /admin/media-library. After you disable the module, both the menu and the list entry are hidden, but the images and the database records are kept, and re-enabling restores them — so you can relax on that point.

2. Every image has a “usage status”

The list shows the storage location (local or R2), dimensions, file size, upload time, and usage status:

  • In use: referenced by body content, product images, or other settings, and cannot be deleted;
  • Unused: can be deleted one at a time, or selected and deleted in bulk.

At the top you can filter by storage location — “All / Local / R2” — and clicking a thumbnail opens the original image in a new window. This “in use” check is the safety valve for deletion: to delete an image that is currently in use, you must first remove its references from body content, products, or settings, and wait until it becomes “Unused”.

Example of a KingCMS X1 product detail page
Product images also count as references; as long as a product still uses an image, that image cannot be deleted.

3. Two-way migration between local storage and R2

Select images and click “Migrate to local” or “Migrate to R2”; the task is created in the background, and the page shows a progress bar, the number completed, and any failed images. Migration is executed image by image by a scheduled task, so you can leave the page and come back to check progress; only one migration task runs at a time.

When the migration finishes, the original image addresses referenced in body content, product images, and other settings are automatically replaced with the new addresses, and the files in the original location are deleted. So do not manually change image addresses while a migration is running — that easily conflicts with the replacement logic.

Before migrating to R2, configure “Settings → Content & Media → Storage”. R2 requires five items: account ID, bucket, Access Key ID, Secret Access Key (stored as a secret and never displayed back), and the public access URL — the last one must begin with https://, otherwise it cannot be saved. If any item is missing, the “Migrate to R2” button is unavailable.

4. What batch deletion actually does

After checking “Select all” or selecting images one by one and clicking “Batch delete”, the system deletes only unreferenced images; images that are in use are skipped, and the result shows how many were deleted and how many were skipped. Deletion removes both the original images and the generated thumbnails, and cannot be undone.

In other words: batch deletion is safe, but it will not “helpfully” delete images that are in use for you; there is no need to worry when you see a skipped count — that is protection.

5. Common questions

  1. Do I have to keep the page open during migration: No, the background scheduled task keeps running.
  2. An image in use cannot be deleted: Remove the reference first and wait for the status to change to “Unused”.
  3. The “Migrate to R2” button is grayed out: The five R2 items are incomplete — especially whether the public address starts with https.
  4. Will images disappear if I disable the module: No, both the records and the files are kept.
  5. Can I change images during a migration: Not recommended; addresses are replaced automatically and conflicts are easy.

6. Suggested cleanup rhythm

Don't wait until the disk is full. A steadier approach is to do it once a quarter: first filter the list to “Unused”, export or note the IDs of the thumbnails you want to delete, then batch delete; afterwards spot-check a few rewritten articles and a few product detail pages to confirm their images are fine. The same goes for storage migration — migrating a whole batch is safer than replacing images piecemeal, because address replacement is done uniformly within the task.

Also, after an R2 migration is complete, change the “Storage method” setting so that newly uploaded images go directly to the new location; if you only migrate old images without changing the default storage, later uploads still land in the original location, which makes the whole exercise pointless.

Summary

Image Management turns “cleaning up the upload directory” into an operation you can reason about: check usage status first, then decide whether to delete or keep; when you need to change storage, migrate the whole batch and addresses are replaced automatically; batch deletion only touches unreferenced images. Filtering by “Unused” and cleaning up on a regular basis saves more trouble than hunting for images in backups afterwards.