Repository navigation
Description
Describe the Bug
Since @payloadcms/storage-vercel-blob moved its @vercel/blob dependency from 0.22.3 to 2.3.1, every media operation that replaces an existing file fails: cropping, any image-editor save, and manually replacing a file on an existing upload doc. New uploads still work, which makes the regression easy to miss.
The admin shows a generic "Something went wrong."; the server throws:
Vercel Blob: This blob already exists, use `allowOverwrite: true` if you want to overwrite it. Or `addRandomSuffix: true` to generate a unique filename.
Root cause: @vercel/blob v2 changed put() to refuse overwriting an existing key unless allowOverwrite: true is passed (in 0.x, overwrite was the default). The adapter's uploadFile never passes it:
// dist/uploadFile.js
const result = await put(fileKey, buffer, {
access,
addRandomSuffix,
cacheControlMaxAge,
contentType: mimeType,
token,
})With addRandomSuffix: false (the default), a crop rewrites the same file key, so it collides by construction — the failure is deterministic, not intermittent.
The client-uploads token route (getClientUploadRoute.js → onBeforeGenerateToken) has the same gap: the token payload doesn't include allowOverwrite, so a direct-to-blob replacement with an unchanged filename fails the same way.
Payload's file-replacing operations are written on the assumption that a storage adapter can overwrite in place (crop fetches the stored file, transforms it, and re-puts it under the same key), so the adapter needs to restore the old semantics:
const result = await put(fileKey, buffer, {
access,
addRandomSuffix,
allowOverwrite: true, // v2 default is false; Payload replaces files in place
cacheControlMaxAge,
contentType: mimeType,
token,
})(and allowOverwrite: true in the onBeforeGenerateToken return for client uploads).
Verified on a production Vercel deployment and in local dev — same deterministic 500 in both. Patching the two call sites with allowOverwrite: true (via pnpm patch) fixes crop/edit/replace with no side effects, and keeps addRandomSuffix: false filenames stable (switching addRandomSuffix on is not a workaround for existing sites — it changes every URL).
To Reproduce
- Fresh Payload project with
vercelBlobStorage({ collections: { media: true }, token })—addRandomSuffixleft at its default (false). - Upload any image to the media collection (works).
- Open the doc, use Crop Image (any crop), save.
- Save fails with a 500; the server logs the
Vercel Blob: This blob already exists…error fromput()called instorage-vercel-blob'suploadFile, invoked fromplugin-cloud-storage'safterChangehook.
Payload Version
3.86.0 (@payloadcms/storage-vercel-blob 3.86.0, resolving @vercel/blob 2.3.1)
Adapters and Plugins
storage-vercel-blob, plugin-cloud-storage
Activity
fix(storage-vercel-blob): allow overwriting existing blob keys (#17383)
patch storage-vercel-blob: allowOverwrite on re-uploads