How to customize Sanity CDN file URLs to be human-readable instead of hash?

1 replies
Last updated: Aug 31, 2021
Hi, I have a question about files: Is it somehow possible to alter the URL to a file in the cdn? I know we can append
?dl=
to ensure a certain filename on a downloaded file, but the URL to the file itself will be a hash of some sort and therefore not really be human-readable. An example:
How it is today:
https://cdn.sanity.io/files/EXAMPLE/test/0a58f9ef059ce5d5995b1ede2d31149dc79d287c.pdf?dl= How I would like it:
https://cdn.sanity.io/files/EXAMPLE/test/event-timetable.pdf?dl=
AI Update

Unfortunately, you cannot change the hash-based path segment in Sanity's CDN file URLs. The hash (like 0a58f9ef059ce5d5995b1ede2d31149dc79d287c.pdf) is content-addressable and fundamental to how Sanity's CDN works - it ensures cache integrity and prevents collisions.

However, there are two approaches you can use to improve the user experience:

1. Vanity Filenames (For Images Only)

For images, Sanity supports vanity filenames where you can append a human-readable name after the hash:

https://cdn.sanity.io/images/PROJECT/DATASET/HASH-WIDTHxHEIGHT.FORMAT/event-timetable.png

Unfortunately, this feature is only available for images, not PDF or other file assets. Files served through cdn.sanity.io/files/ don't support vanity filenames in the path.

2. The ?dl= Parameter (Your Current Approach)

The ?dl= parameter you're already using is the correct and only way to control the download filename for file assets. While it doesn't change the URL path itself, it does set the Content-Disposition header, which determines what filename the browser uses when downloading:

https://cdn.sanity.io/files/PROJECT/DATASET/HASH.pdf?dl=event-timetable.pdf

This is the standard approach for file downloads and works well for SEO and user experience when files are actually downloaded.

Alternative: Proxy Through Your Own Domain

If human-readable URLs are critical for your use case (for SEO or branding), you could:

  1. Create a custom endpoint in your application (e.g., /downloads/event-timetable.pdf)
  2. Map friendly names to the actual Sanity CDN URLs in your code
  3. Redirect or proxy requests to the actual Sanity CDN URL

This gives you full control over the URL structure users see, while still leveraging Sanity's CDN for the actual file delivery.

The hash-based system is intentional - it provides content-addressable storage, automatic deduplication, and reliable caching. While it's not human-readable, the ?dl= parameter ensures users still get meaningful filenames when downloading.

Show original thread
1 reply
Hey there! There isn't a way to change the url of the asset, unfortunately.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?