Skip to content

feat(storage-vercel-blob): add allowOverwrite option#16078

Open
joeliomartini wants to merge 1 commit intopayloadcms:mainfrom
joeliomartini:feat/storage-vercel-blob-allow-overwrite
Open

feat(storage-vercel-blob): add allowOverwrite option#16078
joeliomartini wants to merge 1 commit intopayloadcms:mainfrom
joeliomartini:feat/storage-vercel-blob-allow-overwrite

Conversation

@joeliomartini
Copy link
Copy Markdown

Summary

Adds a new allowOverwrite option to VercelBlobStorageOptions that passes through to all @vercel/blob put() calls — both server-side uploads (handleUpload.ts) and client upload token generation (getClientUploadRoute.ts).

Problem

When using clientUploads: true with addRandomSuffix: false, failed uploads leave orphan blobs in Vercel Blob storage. The blob is created successfully, but Payload's server-side processing (image size generation, generateFileData) can fail with a 400 error — leaving a blob without a corresponding Payload media record.

Subsequent uploads of the same filename then fail with:

Vercel Blob: This blob already exists, use allowOverwrite: true if you want to overwrite it.

This is particularly frustrating because the user has no way to clean up the orphan blob through the Payload admin — the media record was never created, so there's nothing to delete.

Related: #14709

Solution

The @vercel/blob SDK already supports allowOverwrite: true on put() calls, but the Payload adapter didn't expose this option. This PR adds it as a top-level config option:

vercelBlobStorage({
  token: process.env.BLOB_READ_WRITE_TOKEN,
  collections: { media: true },
  allowOverwrite: true, // new option
})

Changes

  • index.ts: Added allowOverwrite to VercelBlobStorageOptions type with JSDoc documentation. Passes it through to both getHandleUpload and getClientUploadRoute.
  • handleUpload.ts: Passes allowOverwrite to the put() call for server-side uploads.
  • getClientUploadRoute.ts: Passes allowOverwrite in the onBeforeGenerateToken return value for client-side uploads.

Default behavior

allowOverwrite defaults to false, preserving the current behavior. No breaking changes.

Adds a new `allowOverwrite` option to `VercelBlobStorageOptions` that
is passed through to all `@vercel/blob` `put()` calls, including both
server-side uploads and client upload token generation.

When a client upload fails partway through (e.g., the blob is created
but Payload's server-side processing returns a 400), an orphan blob is
left behind. Subsequent uploads of the same file then fail with:

  "Vercel Blob: This blob already exists"

Setting `allowOverwrite: true` prevents this error by silently
overwriting the existing blob instead of rejecting the upload.

Refs: payloadcms#14709
@joeliomartini joeliomartini requested a review from denolfe as a code owner March 27, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant