Skip to content

Clarify Static Assets usage in RPC calls #22759

@vladshcherbin

Description

@vladshcherbin

Existing documentation URL(s)

There is no section on how to use static assets in RPC calls. Example:

export default class ImageWorker extends WorkerEntrypoint {
  fetch() {
    return new Response(null, { status: 404 })
  }

  async generateImage(message: string, emoji?: string) {
    this.env.ASSETS.fetch() // WHAT TO PUT HERE ???
  }
}

generateImage does not have request param, doesn't accept filenames (emoji/eyes.png) and wants URL.

Just by pure luck after hours of battles and dances with whistles I've randomly tried url from one line in docs and it WORKED: new URL('https://assets.local/emoji/eyes.png')

How, just HOW can I know assets.local will point to my worker assets...

I've made another github search for assets.local and also found this gem: cloudflare/workers-sdk#8992 (comment)

// Note: according to Cloudflare employees, when fetching against the
// ASSETS binding, the hostname is essentially ignored — anything will
// work, such as example.com, google.com, etc. By apparent convention,
// assets.local is used.

So any domain work same way, e.g. new URL('https://gg/emoji/eyes.png').

HOOOOOW is this not documented?

What changes are you suggesting?

Document usage of static assets inside workers, assets.local domain usage and any other domain behavior.

Additional information

Holy cow guys, I absolutely love cloudflare and how it works, but such things will make me a mad man someday 🧙‍♂️

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions