Remote images via proxy
The delivery proxy fetches images from your existing storage through the Uploadcare CDN, transformations included, without migrating a single file. Existing references keep working; the first request pulls the source in, and subsequent ones hit the CDN cache.
Build a proxified URL
A proxy endpoint is not a CDN base: it is <publicKey>.ucr.io with your key verbatim, not a hashed prefix, and defaultProxyEndpoint builds it. All three styles handle proxy URLs — the builder takes the endpoint as its cdnBase alongside a sourceUrl, and a parsed proxy URL round-trips through any of them. Nor is there a string-level tab: the source URL is embedded in the path, and normalizeModifiers collapses its https:// into https:/, corrupting it.
import { defaultProxyEndpoint, proxyUrl } from '@uploadcare/cdn-url/proxy'
import { preview, resize } from '@uploadcare/cdn-url/ops'
const endpoint = defaultProxyEndpoint('YOUR_PUBLIC_KEY')
// → https://YOUR_PUBLIC_KEY.ucr.io
proxyUrl(endpoint, 'https://yoursite.com/assets/hero.jpg', [
preview(), // no-arg preview marks the chain as processed, see Best practices
resize({ width: 1280 })
])
// → https://YOUR_PUBLIC_KEY.ucr.io/-/preview/-/resize/1280x/https://yoursite.com/assets/hero.jpgimport { CdnUrl } from '@uploadcare/cdn-url/builder'
import { defaultProxyEndpoint } from '@uploadcare/cdn-url/proxy'
import { preview, resize } from '@uploadcare/cdn-url/ops'
new CdnUrl({
cdnBase: defaultProxyEndpoint('YOUR_PUBLIC_KEY'),
sourceUrl: 'https://yoursite.com/assets/hero.jpg',
operations: [preview(), resize({ width: 1280 })]
}).hrefimport { cdn } from '@uploadcare/cdn-url/fluent'
import { defaultProxyEndpoint } from '@uploadcare/cdn-url/proxy'
// no `cdn.base(…)` needed: the endpoint is this call's first argument
cdn
.proxy(
defaultProxyEndpoint('YOUR_PUBLIC_KEY'),
'https://yoursite.com/assets/hero.jpg'
)
.preview()
.resize({ width: 1280 }).hrefOperations sit between the endpoint and the source URL. The source keeps its own query string verbatim.
Custom proxy domains work the same way; pass your endpoint instead:
proxyUrl('https://proxy.yourdomain.com', source, ops)Parsing proxified URLs
parseCdnUrl recognizes the embedded source and returns the proxy kind:
const parsed = parseCdnUrl(
'https://pubkey.ucr.io/-/resize/500x/https://example.com/a.jpg?v=2'
)
// { kind: 'proxy', cdnBase: 'https://pubkey.ucr.io', operations: […], sourceUrl: 'https://example.com/a.jpg?v=2' }There is no uuid: the shape doesn't have one, and TypeScript will tell you so.
Prerequisites and failure modes
- Allow-list the source domain in your project settings first; otherwise the proxy answers
400 Domain is not allowed. - The proxy probes the source with a
HEADrequest before fetching, so your cdnBase server must answer those correctly. - Fetching counts against your project's upload units and storage (it's a
from_urlupload under the hood); the processed variants don't.
Proxy vs uploading
The proxy works well for incremental adoption and content you don't control. Once an image is yours, uploaded and with a uuid, prefer regular CDN URLs: no allow-list, no first-request latency, and group and conversion features all apply.