Add an unstable (v0) "canvas_external_api" POST route for uploading an image blob and getting back the ID and UUID of the created media entity
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3578449. --> Reported by: [effulgentsia](https://www.drupal.org/user/78040) Related to !820 >>> <h3 id="overview">Overview</h3> <p><span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3575874" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3575874</a></span> is adding the ability for the Canvas CLI's <code>push</code> command to push pages, including all of its component instances, from the local json-render representation to the Drupal site. However, it isn't yet able to push component instances with values for image props. That will be done by <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/canvas/issues/3578452" title="Status: Closed (fixed)">#3578452: Include pages with images in the CLI push/pull commands</a></span> which is blocked on this issue.</p> <p>The use case we're trying to enable is while working in a local IDE, to be able to prompt a coding agent to create or change a page, and for the agent to be able to add new image component instances or change existing image component instances to point to new images that the agent finds on the internet, such as on <a href="https://unsplash.com/">https://unsplash.com/</a>. The CLI tool can fetch the images and upload them as blobs to Drupal, so that we don't need Drupal to fetch the remote images directly.</p> <p>The goal of this issue is to provide the back-end API that the CLI can use to upload those images into the Drupal site as media entities.</p> <h3 id="proposed-resolution">Proposed resolution</h3> <p>Create a route and controller for a POST method where:</p> <ul> <li>The request body contains the image blob, the image filename, and alt text.</li> <li>If all validation passes, the controller generates a new file entity and media entity. The filename created on the server can be different than the filename in the request body, just like when uploading to an image field through Drupal's regular UI.</li> <li>The response returns the media entity's ID and UUID.</li> <li>If it's easy enough to do, it would be nice to also return the <code>inputs_resolved</code> of what a Canvas image prop that uses this new media entity would get, so that the CLI can update its local json-render files accordingly. If that's tricky, then we can open a follow-up to discuss options for how to do that or work around the need for it.</li> <li>Drupal core's <code>FileUploadHandler</code> is used (see <a href="https://www.drupal.org#comment-16505736">comment #2</a>).</li> </ul> <p>We do not yet need other HTTP methods (GET, PATCH, DELETE) or a listing API. Those can be done in other issues if/when they're needed.</p> > Related issue: [Issue #1927648](https://www.drupal.org/node/1927648) > Related issue: [Issue #2940383](https://www.drupal.org/node/2940383) > Related issue: [Issue #3578452](https://www.drupal.org/node/3578452) > Related issue: [Issue #3532574](https://www.drupal.org/node/3532574) > Related issue: [Issue #3575872](https://www.drupal.org/node/3575872)
issue