Set alt text at upload time, not later

MediaBeginner~5 min

Before you start

A connected site with the upload-media write ability enabled, plus set-featured-image if you want the new image put on a post. Uploads must be jpg, png, gif, or webp.

Every media library full of blank alt text was filled one hurried upload at a time. Nobody sets out to skip it. The field is just one step away from the thing you actually came to do, so it waits, and then there are four hundred of them and it becomes a project.

The upload ability takes the alt text with the file, in the same call. That turns the description from a follow-up task into part of the upload, which is the only version of this that survives contact with a busy week.

The prompt
Upload [the image I just gave you] to the media library and set its alt text
in the same call. The upload takes the file as base64 and it accepts an alt
parameter, so please do not upload it bare and describe it afterwards.
The image shows [what it shows]. Draft short, descriptive alt text from that.
Before you upload, show me the filename, the format, and the alt text you plan
to store, and wait for my go-ahead. It has to be a jpg, png, gif, or webp.
Once it is in, [set it as the featured image on post ID 142], then read the
attachment back so I can confirm the alt text saved.

Why this is safe to run

Most of the safety here sits in the format rule. The upload takes base64 data rather than a link, and the plugin decides what the file is by reading its bytes, not by trusting the filename or the type the caller claims. Only jpg, png, gif, and webp get through, so an SVG or anything else stops at the door with nothing written. The name you pass is reduced to a sanitized basename and given the extension that matches what the bytes actually are.

Everything else is deliberately small. The upload adds one new image and changes nothing already in your library. Setting the featured image points one post at that attachment and leaves the body and the publish status alone. Both writes stay off until you enable them, both are checked against the capability of the user you bound the agent to, and both land in the Activity Log. The read at the end costs nothing and closes the loop, since it shows you the alt text as stored rather than as the agent remembers writing it.

Already connected? Skip the paste. Ask your agent to upload the image with its alt text set in the same call, and it runs the same describe, approve, upload flow on your own site.

How it works

  1. Give the agent the image and tell it what the image shows.
  2. It reads the file as base64 and drafts short alt text from your description.
  3. It shows you the filename, the format, and the alt text it will store, and waits.
  4. On approval it uploads the image with the alt text set in the same call.
  5. If you named a post, it sets the new attachment as that post's featured image.
  6. It reads the attachment back so you can confirm the alt text saved.

Questions

Why set alt text during the upload instead of after?
Fewer calls and no gap. upload-media takes an alt parameter alongside the file, so the image is never sitting in the library undescribed. Doing it afterwards works too, through update-media, but that is a second write and it is the step everyone skips.
What will it accept?
jpg, png, gif, and webp, checked from the actual bytes rather than the filename or a claimed type. SVG is rejected outright. The stored filename is reduced to a sanitized basename, and the extension is replaced with the one matching the detected type.