Hi there. I am Vincent from Vercel. I work on everything related to Vercel Blob together with Luis.
tl;dr; We propose to change the way put/upload are working in a new version of @vercel/blob
How it works today
Vercel Blob is an object storage service, you upload a file and then get a URL so you can use it on your website and applications.
Vercel Blob has been in beta for 1.5 years, and we’re preparing it for prime time. As part of this effort, based on your feedback, we’d like to (maybe) change some of the defaults of our SDK (@vercel/blob).
Since the beginning, our SDK has worked this way:
import { put } from '@vercel/blob';
const blob = await put('file.jpg', File);
console.log(blob.url);
You then end up with a url like: https://vxvc8s3stpz0gugh.public.blob.vercel-storage.com/file-8nFEAMuXYI0OPSmMbNc56bU9ncBVWa.jpg
. Where 8nFEAMuXYI0OPSmMbNc56bU9ncBVWa
is what we call a random suffix.
This is a useful feature as you never have to worry about conflicts in URLs.
addRandomSuffix: false
The downside of random suffixes is that you need to store the full URL on your side, you can’t reconstruct a URL just from “file.jpg” since there’s a random part.
This is why, some customers requested more control over the random suffix: they wanted to disable it. We introduced an option for that, addRandomSuffix: boolean
:
import { put } from '@vercel/blob';
const blob = await put('user1337/avatar.jpg', File, { addRandomSuffix: false });
console.log(blob.url);
The blob.url
is now https://vxvc8s3stpz0gugh.public.blob.vercel-storage.com/user1337/avatar.jpg
. There’s no random suffix. And you only need the “user1337” and “avatar.jpg” information in your database to reconstruct this url (you can construct it “statically”).
To cache or not to cache
The downside and feature of no random suffix is that now you can override files easily. So you could update user1337’s avatar for example. There’s a catchcache though: files in Vercel Blob have a cache, both at the edge (s-maxage) and in browsers (max-age) so any browser that previously downloaded the user avatar won’t see the new avatar before some time.
That’s why you need to be careful when deciding to not use random suffixes as this could lead to inconsistencies. (Note: you can also configure Vercel Blob cache to lower values).
The future of @vercel/blob
A recent internal discussion followed this pattern (cc @styfle): “Since random suffixes are sometimes not wanted, since overriding blobs can trigger weird consistency behaviors, should we walk users through gradual understanding and disabling of these features instead of activating them all magically?”.
As such, we’re proposing to update put/upload to work this way:
// Default behavior, no random suffixes If file.png already exists you'll get an error.
put('file.png', File) ;
// If file.png already exists, it will override it.
put('file.png', File, { override: true });
// Allows you to mimic the original behavior of random suffix by default
put('file.png', File, { addRandomSuffix: true });
We think these changes will provide a better understanding of how Blob works and what you can do with it.
Tell us what you think