DEV Community

Casper Tran
Casper Tran

Posted on

Substack image URLs: the original file is URL-encoded inside the address

An image in a Substack post comes from substackcdn.com, and its address carries two things at once: the transform options and, URL-encoded at the end, the file Substack actually stores.

https://substackcdn.com/image/fetch/$s_!JlLK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60f1843e-..._2048x1152.png
Enter fullscreen mode Exit fullscreen mode

The part before the last slash is for the image server. w_1456,c_limit scales the image down to at most 1456 px wide, f_auto lets the server pick the format, and q_auto:good picks the compression. The page's srcset also lists w_424, w_848 and w_1272, each once with f_auto and once with f_webp. The part after the slash is an S3 URL, and the numbers at the end of the file name are its pixel size.

Most post images are also wrapped in a link to the same address without w_1456,c_limit.

Four copies of the same image

I took six images from three public posts (Noahpinion, Astral Codex Ten, The Pragmatic Engineer) and fetched each address with curl, once with Chrome's image Accept header and once without. Here are the two largest uploads:

Address PNG, 2048x1152 upload PNG, 2360x1338 upload
w_848,c_limit,f_webp 848x477, WebP, 86 KB 848x481, WebP, 16 KB
w_1456,c_limit,f_auto (in the post) 1456x819, JPEG, 246 KB 1456x825, JPEG, 62 KB
No w_ (the link around the image) 2048x1152, JPEG, 412 KB 2360x1338, JPEG, 108 KB
Decoded S3 URL 2048x1152, PNG, 5.3 MB 2360x1338, PNG, 410 KB

Images narrower than 1456 px came back at their own size from the in-post copy, and for all six the link copy was byte for byte the same file as a w_2912 copy I built by hand. Asking for a wider image never enlarges anything.

What surprised me

The Accept header changed nothing. Both requests got identical bytes every time, and f_auto sent JPEG or PNG even when the request offered AVIF and WebP. The server varied its answer only by Origin.

f_auto also turned two of the five PNGs into JPEGs, and the link copy did the same. So "full size" and "original" are two different things here: dropping w_ gets you every pixel, but only the S3 file kept the stored format for all six. Its pixel size matched the numbers in its name every time.

Getting the stored file

Take everything after the last /, decode it, and request that:

const src = img.currentSrc;
const original = decodeURIComponent(src.slice(src.lastIndexOf('/') + 1));
// https://substack-post-media.s3.amazonaws.com/public/images/..._2048x1152.png
Enter fullscreen mode Exit fullscreen mode

If the decoded value does not start with https://substack-post-media.s3.amazonaws.com/, the image came from somewhere else (an embed, a sponsor banner) and the trick does not apply.

I keep a list of these URL edits for about 50 sites at https://github.com/aboivz/fullsize-image-urls, and the steps for doing it by hand are here: https://pixlasso.com/guides/download-images-from-substack?src=devto. I make PixLasso, a browser extension that saves a page's images; it has no Substack rule yet, so it saves the link copy, not the S3 file.

Top comments (0)