Upload media with the CLI
With hakocms-cli media upload, you can upload many images and files at once. Uploaded media appears in [メディア](Media) in the admin.
Prerequisites
Section titled “Prerequisites”- You are logged in with
hakocms-cliand have set the space (Log in with the CLI) - You have a role that can upload media (owner, admin, or editor)
- There is a limit on the size of a single file (Usage limits)
Upload in bulk
Section titled “Upload in bulk”Pass the file names in a list. You can also use the shell’s *.
hakocms-cli media upload photos/*.pngThe CLI sends the files one at a time and shows progress after each one. At the end, it shows a list of the uploaded media.
uploaded 1/2: mountain.pnguploaded 2/2: sea.pngID FILE NAME KIND URL1edtz5vle5gg mountain.png image https://<hostname>.hakocms.net/media/1edtz5vle5gg/mountain.pngk323zqmuvvvs sea.png image https://<hostname>.hakocms.net/media/k323zqmuvvvs/sea.png- If an upload fails partway, the CLI stops there. The files sent before that remain. Send again starting from the file that failed
- If you send the same file again, it is added as a separate media item. Before you send again, check in the admin or with
media listthat the file is not already uploaded
When you upload, you can add alt text and tags. Both are added to every file you pass. Pass tags as a JSON array of strings.
hakocms-cli media upload photos/*.png --alt "旅行の写真" --tags '["travel","2026"]'Change alt text and tags
Section titled “Change alt text and tags”hakocms-cli media update <media ID> --alt 海の写真 --tags '["sea","2026"]'--tags replaces the current tags instead of adding to them.
Find media
Section titled “Find media”hakocms-cli media list --tag 2026 --all # By taghakocms-cli media list --query sea # By file name, alt text, or taghakocms-cli media list --kind file # Only files that are not imagesPut images in an entry’s image field
Section titled “Put images in an entry’s image field”Put a media URL in an image field in the form {"url": "<URL>"}. Use the URL shown when you upload.
This example is for a content type photos with an image field image. For each file, it uploads the file, then creates an entry that contains that image.
for f in photos/*.png; do url=$(hakocms-cli media upload "$f" --jq '.[0].url') hakocms-cli entries create -t photos \ --set "title=$(basename "$f" .png)" \ --set "image={\"url\":\"$url\"}" --jq .iddoneHako CMS fills in the width and height from the media.
{ "url": "https://<hostname>.hakocms.net/media/pdegl1xwddch/mountain.png", "width": 1200, "height": 800 }You cannot use media from another space. For a multiple-image field (mediaList), put an array of the same shape.
Check whether media is used
Section titled “Check whether media is used”Before you delete media, check which entries use it.
hakocms-cli media usages <media ID>The content types and IDs of the entries that use it are shown. If it is not used anywhere, [] is shown.
Delete
Section titled “Delete”hakocms-cli media delete <media ID>The CLI asks you to confirm the deletion. To delete from a script, add --force. The URL of deleted media stops working immediately. This cannot be undone.
You cannot delete media that entries use. First check the entries that use it with media usages, and remove the media from those entries.
Verify
Section titled “Verify”In [メディア](Media) in the admin, check that the uploaded files are listed and that they have the alt text and tags.
Related
Section titled “Related”- Upload media: working in the admin
- Transform images (size, format)
- CLI command reference: media