How to Change Storage Without Breaking Your Blog’s Image Links
Storage prices can change. Give your images an address on your own domain and keep their file paths, so old posts still work when you switch providers.
I choose where to store my blog images based on what it costs today. If the free tier covers what I use, that’s where I’ll start. If I outgrow it or find a cheaper provider, I want to move the files and have my old posts open as usual.
When I moved my blog’s images to a domain I own, copying files was the easy part. The slow part was finding everything that still used the old addresses. If I were starting over, I’d give my images their own domain from day one. The posts could keep those links, and I could decide where to store the files later.
Why isn’t copying the images enough?
I used to upload an image to Vercel Blob and paste the link it gave me into a post. I only needed a few images at a time, so this was convenient. By the time I wanted to switch storage, those links were in post bodies, cover images, and old versions. Some had gone out with drafts I’d shared elsewhere.
Copying an image to another provider gives it a new address. The old post still looks for it at the original one. I can update links on my site, but I can’t change a link someone has already bookmarked or shared. Anyone using the provider’s original URL still needs that old storage to stay up.
Give posts an image address you control
My blog and its admin now load images from assets.chankay.com. If a post uses /media/cover.png, the browser requests that path on my asset domain. A Cloudflare Worker fetches the file at the same path from whichever storage provider I’m using. The post only needs the domain and the file path.
The Worker uses the incoming path as-is. I can copy the folders and filenames together and avoid keeping a table of old and new addresses. I’m still using Vercel Blob. I can now choose what goes in a post’s image URL independently of where I store the file.
What do I have to do next time I move?
When I compare providers, I also look at whether I can export files in bulk and what it will cost to transfer them out. Once I pick one, I can copy the files under the same paths, check that everything made it over, and point both image reads and uploads to the new storage. Posts that use my asset domain can keep their links. The old provider URLs that people already have still depend on the old store, so I’ll have to account for them before shutting it down.
Keeping a path also helps with everyday edits. If I fix a typo in a diagram, I can keep its filename so the same link shows the corrected image. If two posts use that diagram, both will pick up the change. If I only want to change one post, I’ll upload a separate image and update that post’s reference.
I’ll still compare prices the next time I choose storage. When I add an image to a post, I want its address to be one I can keep. When it’s time to move, I can take the files with me and leave readers’ links where they are.
Discussion
Sign in with GitHub to comment. All language versions share this discussion.
View discussions on GitHub