Skip to content

Add support for hosted images api operations in the Images Binding#10153

Merged
emily-shen merged 4 commits intocloudflare:mainfrom
mglewis:mattl/IMAGES-1700-add-hosted-method-to-images-binding
Mar 2, 2026
Merged

Add support for hosted images api operations in the Images Binding#10153
emily-shen merged 4 commits intocloudflare:mainfrom
mglewis:mattl/IMAGES-1700-add-hosted-method-to-images-binding

Conversation

@mglewis
Copy link
Member

@mglewis mglewis commented Jul 31, 2025

This PR is the counterpart for this workerd change that adds support for various CRUD operations for Cloudflare Hosted Images. This replicates existing functionality already available through the Images API.

Implementation Details

This PR includes a mock implementation (packages/miniflare/src/workers/images/images.worker.ts) of the hosted images backend that uses an in-memory map for local development.

Note that support for metadata filtering in the list method will be added in a followup MR

Regenerated workerd.ts with pnpm run capnp:workerd

Testing

The tests in fixtures/vitest-pool-workers-examples/images/ have been expanded to cover the new CRUD operations. As the accompanying workerd change has just been merged, testing locally was accomplished by pointing at my local branch:

$ cd /fixtures/vitest-pool-workers-examples 
$ export MINIFLARE_WORKERD_PATH="/Users/mattl/code/workerd/bazel-bin/src/workerd/server/workerd"
$ pnpm test images
...
   ✓ Images binding > can upload an image 7ms
   ✓ Images binding > can upload a base64-encoded image 6ms
   ✓ Images binding > can get image metadata 4ms
   ✓ Images binding > can get image data 3ms
   ✓ Images binding > can update image metadata 4ms
   ✓ Images binding > can delete an image 5ms
   ✓ Images binding > can list images 10ms
   ✓ Images binding > returns null for non-existent image metadata 3ms
   ✓ Images binding > returns error for non-existent image blob 3ms
   ✓ Images binding > can return image info 109ms

 Test Files  1 passed (1)
      Tests  10 passed (10)

To sanity check the local development experience, workerd was compiled locally and run against our local miniflare with a barebones test worker:

export default {
  async fetch(request, env: Env, ctx): Promise<Response> {
    const originalImage = await fetch("https://images.mglewis.uk/snail.jpg");
    const uploadedImageMetadata = await env.IMAGES.hosted.upload(originalImage.body!);
    const uploadedImage = await env.IMAGES.hosted.image(uploadedImageMetadata.id);
    const result = await env.IMAGES.input(uploadedImage)
      .transform( { width: 500, rotate: 180 })
      .output({ format: "image/webp" });
    return result.response();
  },
} satisfies ExportedHandler<Env>;

Running this test worker against our local workerd branch:

$ export MINIFLARE_WORKERD_PATH="$HOME/code/workerd/bazel-bin/src/workerd/server/workerd"
$ cd $HOME/code/example-worker
$ node $HOME/code/workers-sdk/packages/wrangler/wrangler-dist/cli.js dev
...
[wrangler:info] GET / 200 OK (270ms)

Hurrah, our snail has been successfully uploaded, fetched and rotated!
image

Note that running wangler with the --remote flag currently fails with a 500. I have a bit of a gap in understanding here, but believe that this should be possible to get working once we have the necessary internal systems correctly configured.

$ node $HOME/code/workers-sdk/packages/wrangler/wrangler-dist/cli.js dev --remote
...
[wrangler:info] GET / 500 Internal Server Error (3105ms)
✘ [ERROR] env.IMAGES.upload is not a function
  • Tests
    • Tests included/updated
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This hasn't been officially released yet

Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Jul 31, 2025

🦋 Changeset detected

Latest commit: be951c1

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 31, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10153

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10153

miniflare

npm i https://pkg.pr.new/miniflare@10153

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10153

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10153

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10153

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10153

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10153

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@10153

wrangler

npm i https://pkg.pr.new/wrangler@10153

commit: 02cef36

@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch 2 times, most recently from 07e953d to de6de22 Compare January 20, 2026 16:26
@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch 11 times, most recently from efca0bb to 94d5780 Compare February 9, 2026 15:46
@mglewis mglewis marked this pull request as ready for review February 9, 2026 15:51
@mglewis mglewis requested a review from a team as a code owner February 9, 2026 15:51
devin-ai-integration[bot]

This comment was marked as resolved.

@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch from 94d5780 to e054df5 Compare February 9, 2026 15:59
@mglewis mglewis changed the title draft: Add support for the new hosted method in the images binding Add support for the new hosted method in the images binding Feb 9, 2026
@mglewis mglewis changed the title Add support for the new hosted method in the images binding Add support for hosted images api operations in the Images Binding Feb 9, 2026
@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch from e054df5 to 0539df3 Compare February 11, 2026 21:13
devin-ai-integration[bot]

This comment was marked as resolved.

@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch 2 times, most recently from dcce256 to 30ff241 Compare February 13, 2026 15:13
@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch 2 times, most recently from 2a03d60 to de7c152 Compare February 26, 2026 10:46
@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch 8 times, most recently from 6e86169 to 5b2aa4d Compare February 26, 2026 16:08
@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch from 897f0f1 to 8640b42 Compare February 26, 2026 20:42
Copy link
Contributor

@emily-shen emily-shen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally lgtm, could you get a review from the images team too to double check the implementation matches your team's expectations?

@mglewis mglewis force-pushed the mattl/IMAGES-1700-add-hosted-method-to-images-binding branch from f26504a to 2e02579 Compare February 27, 2026 20:35
@mglewis
Copy link
Member Author

mglewis commented Mar 2, 2026

generally lgtm, could you get a review from the images team too to double check the implementation matches your team's expectations?

I've had a chat with @dochne (Images colleague) and he's happy with the implementation.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 2, 2026
Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>
@emily-shen emily-shen merged commit 5f7aaf2 into cloudflare:main Mar 2, 2026
32 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants