Skip to content

Image: sideload external images on the server when uploading to the library#29

Open
adamsilverstein wants to merge 2 commits into
fix/preview-interstitial-dip-isolationfrom
fix/external-image-server-sideload
Open

Image: sideload external images on the server when uploading to the library#29
adamsilverstein wants to merge 2 commits into
fix/preview-interstitial-dip-isolationfrom
fix/external-image-server-sideload

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jun 22, 2026

Copy link
Copy Markdown
Owner

What

Extends the attachments REST endpoint (POST /wp/v2/media) to accept an optional url parameter. When present, the server downloads the remote image with download_url() and sideloads it, storing only the original (no sub-sizes), instead of the browser fetching the bytes and posting a blob.

The image block "Upload to Media Library" action and the pre-publish "External media" panel use this server-side path through a new mediaSideloadFromUrl editor setting.

Why

When the editor is cross-origin isolated — which client-side media processing requires (Document-Isolation-Policy: isolate-and-credentialless) — the previous client-side window.fetch() of the remote image is blocked by CORS for hosts that do not send the needed headers, so external uploads silently failed. Letting the server fetch the URL avoids browser CORS entirely.

Stacked on WordPress#79342 (which introduces the editor cross-origin isolation).

Testing

  • test/e2e/specs/editor/blocks/image.spec.js "should upload external image to media library" and "should upload through prepublish panel" pass with cross-origin isolation active (Chrome 148).
  • Direct REST dispatch confirms 201 with no sub-sizes (empty media_details.sizes), so the front end serves only the original (no srcset).
  • phpcs and JS lint clean.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7e4b23c-197f-48ec-950c-2dcd71b64150

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/external-image-server-sideload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ibrary

Uploading an image inserted by URL to the media library read the remote
image's bytes in the browser with window.fetch and posted the resulting blob.
Under cross-origin isolation, which client-side media processing requires,
that cross-origin fetch is blocked, so the upload could not complete.

Accept a `url` parameter on the attachments create endpoint and sideload the
remote image on the server instead, storing only the original file (no
sub-sizes). The image block and the pre-publish external-media panel use this
path through a new mediaSideloadFromUrl editor setting, so external uploads
work regardless of cross-origin isolation. The now-unused client-side fetch
helper is removed.
@adamsilverstein adamsilverstein force-pushed the fix/external-image-server-sideload branch from 610d035 to e2e1a55 Compare June 22, 2026 15:58
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

Size Change: -261 B (0%)

Total Size: 8.6 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 324 kB -144 B (-0.04%)
build/scripts/editor/index.min.js 472 kB -117 B (-0.02%)

compressed-size-action

Cover the server-side external image sideload path that backs the
cross-origin-isolation fallback:

- PHP: exercise the `url` param branch on POST /wp/v2/media, asserting
  it sideloads the remote image, generates no sub-sizes when
  generate_sub_sizes is false, attaches to the parent post, propagates
  download errors, and registers the `url` arg on the creatable route.
- JS: unit test mediaSideloadFromUrl for the request shape, attachment
  transform, post/wp_id resolution, and error handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant