payload icon indicating copy to clipboard operation
payload copied to clipboard

storage-vercel-blob: crop / image edit / file replace always 500s — @vercel/blob v2 needs allowOverwrite: true

Open mishery97 opened this issue 4 months ago • 0 comments

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

  1. Fresh Payload project with vercelBlobStorage({ collections: { media: true }, token }) — addRandomSuffix left at its default (false).
  2. Upload any image to the media collection (works).
  3. Open the doc, use Crop Image (any crop), save.
  4. Save fails with a 500; the server logs the Vercel Blob: This blob already exists… error from put() called in storage-vercel-blob's uploadFile, invoked from plugin-cloud-storage's afterChange hook.

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

mishery97 avatar Jul 17 '26 09:07 mishery97