Skip to content

Add support for Cloudflare Images operations in the images binding#5912

Merged
danlapid merged 5 commits intocloudflare:mainfrom
mglewis:mattl/images-binding-rpc-support
Feb 25, 2026
Merged

Add support for Cloudflare Images operations in the images binding#5912
danlapid merged 5 commits intocloudflare:mainfrom
mglewis:mattl/images-binding-rpc-support

Conversation

@mglewis
Copy link
Member

@mglewis mglewis commented Jan 16, 2026

Currently the Images Binding only supports info and transform operations. This PR introduces support for the following Hosted Images endpoints that are already available via the images api:

The images binding has recently been switched to a direct binding, so whilst info and transform are still handled by fetcher.fetch the new endpoints for managing Hosted Images pass through via RPC.

Sample implementation

Once released, we'd expect users to be able to write worker code that looks something like

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Upload an image
    const imageData = await fetch('https://example.com/photo.jpg');
    const uploaded = await env.IMAGES.hosted.upload(imageData.body!, {
      filename: 'photo.jpg',
      metadata: { source: 'example' },
    });

    // List images
    const list = await env.IMAGES.hosted.list({ limit: 10 });
    console.log('Images:', list.images.length, 'Complete:', list.listComplete);

    // Update image
    const updated = await env.IMAGES.hosted.update(uploaded.id, {
      metadata: { source: 'example', edited: true },
    });

    // Get image metadata
    const metadata = await env.IMAGES.hosted.details(uploaded.id);
    console.log('Got:', metadata?.filename);
    
    // Delete image
    const deleted = await env.IMAGES.hosted.delete(uploaded.id);
    console.log('Deleted:', deleted);
    return new Response('Done!');
  },
};

Reviewer Considerations

  • This change is coupled tightly with our upstream images api change. A decision has been made to try and keep as much logic in the upstream as possible with the only new upload method having having a non trivial implementation (to leverage workerd's base64 decoding support)
  • In the future we may also want to do away with images-api.ts in its entirety and move the existing transformation logic into our upstream images api
  • After discussion with the team we've opted to go for namespacing the new methods so that they are accessed as follows env.IMAGES.hosted.list(). We are hopeful that will more clearly disambiguate their function to users and give us more flexibility on the addition of new methods to the binding in the future.

Next Steps

  • We still need to make the edgeworker config service inject the accountId into ctx.props
  • Workers sdk / wrangler / miniflare support

@github-actions
Copy link

github-actions bot commented Jan 16, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@mglewis
Copy link
Member Author

mglewis commented Jan 16, 2026

I have read the CLA Document and I hereby sign the CLA

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 16, 2026

Merging this PR will improve performance by 19.43%

⚡ 1 improved benchmark
✅ 69 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
jsonResponse[Response] 47.5 µs 39.8 µs +19.43%

Comparing mglewis:mattl/images-binding-rpc-support (72de7ba) with main (1a28cb8)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@mglewis mglewis force-pushed the mattl/images-binding-rpc-support branch from a721698 to cb83759 Compare January 16, 2026 13:14
github-actions bot added a commit that referenced this pull request Jan 16, 2026
@mglewis mglewis force-pushed the mattl/images-binding-rpc-support branch from af8444f to 826c28b Compare February 11, 2026 21:26
@mglewis mglewis marked this pull request as ready for review February 12, 2026 16:03
@mglewis mglewis requested review from a team as code owners February 12, 2026 16:03
@mglewis mglewis force-pushed the mattl/images-binding-rpc-support branch 6 times, most recently from fe76497 to 8c387e5 Compare February 24, 2026 10:50
@mglewis mglewis force-pushed the mattl/images-binding-rpc-support branch from 0ff70f1 to 98e8e43 Compare February 24, 2026 15:19
@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.62%. Comparing base (1a28cb8) to head (72de7ba).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5912      +/-   ##
==========================================
- Coverage   70.63%   70.62%   -0.02%     
==========================================
  Files         413      413              
  Lines      109828   109828              
  Branches    18098    18098              
==========================================
- Hits        77578    77565      -13     
- Misses      21440    21455      +15     
+ Partials    10810    10808       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mglewis mglewis force-pushed the mattl/images-binding-rpc-support branch 3 times, most recently from 7559567 to 32ad976 Compare February 25, 2026 16:31
@mglewis mglewis force-pushed the mattl/images-binding-rpc-support branch from d3dc775 to 72de7ba Compare February 25, 2026 20:20
@danlapid danlapid merged commit 978416b into cloudflare:main Feb 25, 2026
17 of 18 checks passed
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.

5 participants