feat(storage-vercel-blob): add allowOverwrite option#16078
Open
joeliomartini wants to merge 1 commit intopayloadcms:mainfrom
Open
feat(storage-vercel-blob): add allowOverwrite option#16078joeliomartini wants to merge 1 commit intopayloadcms:mainfrom
joeliomartini wants to merge 1 commit intopayloadcms:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
allowOverwriteoption toVercelBlobStorageOptionsthat passes through to all@vercel/blobput()calls — both server-side uploads (handleUpload.ts) and client upload token generation (getClientUploadRoute.ts).Problem
When using
clientUploads: truewithaddRandomSuffix: 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:
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/blobSDK already supportsallowOverwrite: trueonput()calls, but the Payload adapter didn't expose this option. This PR adds it as a top-level config option:Changes
index.ts: AddedallowOverwritetoVercelBlobStorageOptionstype with JSDoc documentation. Passes it through to bothgetHandleUploadandgetClientUploadRoute.handleUpload.ts: PassesallowOverwriteto theput()call for server-side uploads.getClientUploadRoute.ts: PassesallowOverwritein theonBeforeGenerateTokenreturn value for client-side uploads.Default behavior
allowOverwritedefaults tofalse, preserving the current behavior. No breaking changes.