Skip to content

CDN URL anatomy ​

Every Uploadcare CDN URL follows one structure. Once you know it, the parser's output (and the rest of this library) is obvious.

A file URL ​

https://1s4oyld5dc.ucarecd.net/c2499162-…-47e858/-/crop/640x480/-/preview/400x400/photo.jpg
└──────┬───────────┘└─────┬───────────┘└──────────┬──────────────────┘└───┬────┘
     cdnBase              uuid                operations               filename
  • cdnBase: scheme + host, no path
  • uuid: the file id
  • operations: zero or more -/name/params/ directives, applied in order as a pipeline
  • filename: optional, anything after the last operation without a trailing slash

One directive is an operation (resize/300x); the whole serialized run of them is the modifiers (-/resize/300x/-/blur/10/), which is the word Uploadcare's API uses for a file's stored transformation string (cdnUrlModifiers). This library parses modifiers into operations and serializes them back — see the string-level API for working with the string form directly.

parseCdnUrl returns exactly these fields, discriminated by kind:

ts
const parsed = parseCdnUrl(url)
// parsed.kind: 'file' | 'group' | 'group-element' | 'archive' | 'proxy'

The shape only has the fields its kind allows, and TypeScript narrows on kind:

kindFields
fileuuid, conversion, operations, filename, search, hash
groupgroup: { uuid, count }, no operations, by CDN design
group-elementgroup, nth, operations, filename, search, hash
archivegroup, archive (the format), filename, no operations
proxysourceUrl, operations; the source keeps its own query/hash

All kinds carry cdnBase.

Domains ​

KindHostNotes
legacyucarecdn.comthe original shared domain
prefixed<prefix>.ucarecd.netper-project subdomain, computed from your public key. Yes, ucarecd.net is a different zone than ucarecdn.com, not a typo
customcdn.example.comyour CNAME
proxy<pubkey>.ucr.iodelivery proxy endpoints
ts
import { detectDomainKind } from '@uploadcare/cdn-url'

detectDomainKind('https://1zlmtnsbgr.ucarecd.net') // → 'prefixed'

The parser and serializer work identically on all of them. The cdnBase is just a field, which makes rebasing between domains a one-liner. For choosing the base you build with — and deriving the prefixed one from your public key — see The CDN base.

Group URLs ​

A group id is a uuid with a file count: :uuid~3. Group roots list the files and cannot carry operations; individual files are addressed with nth (zero-based) and can:

https://1s4oyld5dc.ucarecd.net/:uuid~3/                          group root
https://1s4oyld5dc.ucarecd.net/:uuid~3/nth/1/-/resize/256x/      second file, resized
https://1s4oyld5dc.ucarecd.net/:uuid~3/archive/zip/all.zip       originals as an archive

See Groups & archives.

Proxy URLs ​

The delivery proxy fetches remote sources through the CDN. Operations sit between the endpoint and the embedded source URL, which keeps its own query string:

https://pubkey.ucr.io/-/preview/-/resize/500x/https://example.com/image.jpg?v=2
└────────┬──────────┘└──────────┬───────────┘└──────────────┬─────────────────┘
       cdnBase              operations                    sourceUrl

See Remote images via proxy.

Conversion paths ​

Two different beasts, easy to confuse:

  • gif2video is a URL, an on-the-fly CDN operation: https://…/:uuid/gif2video/-/format/webm/. Note there's no -/ between the uuid and the prefix.
  • video and document are paths, not URLs: /:uuid/video/-/size/720x540/ strings you submit to the REST convert API. The library builds them with videoPath / documentPath and deliberately returns no domain.

The parser still understands /:uuid/video/… inside a full URL, because finished conversion jobs are addressable on the CDN that way.

Query strings and fragments ​

?token=… (secure delivery signatures) and #fragments are preserved verbatim through parse → serialize. The library never generates tokens. Remember that editing operations invalidates an existing signature, since it was computed over the old path.