urlTransform rewrites the public URL the plugin generates for a file — add query parameters, a cache-busting timestamp, or take full control with a custom function.
payload.config.ts
urlTransform takes one of four forms:
false(default): no transform.true: on a collection, use the globalurlTransform. At the top level it changes nothing.- An object:
appendTimestampandqueryParams. - A function: you build the URL yourself. See Custom transform function.
Simple transform
Custom transform function
For full control, pass a function asurlTransform. It replaces appendTimestamp and queryParams — you build the URL yourself.
Return the final URL string.
What baseUrl is
urlTransform runs in both access-control modes — it always rewrites the url field. What changes is the base URL it starts from, which matters when you write a transform function:
Sharp dynamic resizing
With Payload access control on, image URLs go through Payload’s/api/<collection>/file/<filename> route. If you turn on dynamic resizing in sharpTransformer({ dynamic: true }) from @payloadcms/transformer-sharp, Sharp takes every request on that route that has a width, height or withoutEnlargement query parameter. This applies to JPEG, PNG, GIF, WebP, TIFF and AVIF files in the collections that dynamic covers.
For such a request, Payload fetches the original file from Bunny without the query string, and Sharp resizes it on your server. So none of the query parameters reach Bunny’s Image Optimizer, not even ones Sharp does not know, such as quality. Sharp also returns 400 for a value it does not accept, for example width=abc.
To keep resizing on Bunny, do one of these:
- Leave
dynamicoff, which is the default. - Limit it with
sharpTransformer({ dynamic: { collections: [...] } })to collections that do not use Optimizer parameters. - Set
disablePayloadAccessControl: trueon the collection, so its URLs point straight at the Bunny CDN.