feat(storage-vercel-blob): add allowOverwrite option (re-open of #16078)#16522
Open
joeliomartini wants to merge 2 commits intopayloadcms:mainfrom
Open
feat(storage-vercel-blob): add allowOverwrite option (re-open of #16078)#16522joeliomartini wants to merge 2 commits intopayloadcms:mainfrom
joeliomartini wants to merge 2 commits 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
Adds allowOverwrite to extraClientHandlerProps and the VercelBlobClientUploadHandler type/destructuring for consistency with addRandomSuffix.
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 (uploadFile.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
This is ported from #16078 to the current package structure (the storage-vercel-blob package was refactored in #16231 —
handleUpload.tsis nowuploadFile.ts, with a newadapter.tswiring layer):index.ts: AddedallowOverwritetoVercelBlobStorageOptionstype with JSDoc, included indefaultUploadOptions, passed to bothcreateVercelBlobAdapterandgetClientUploadRoute, included inextraClientHandlerProps.uploadFile.ts: AddedallowOverwritetoUploadFileArgsand passed it to theput()call for server-side uploads.adapter.ts: AddedallowOverwritetoCreateVercelBlobAdapterArgsand passed it through touploadFile.getClientUploadRoute.ts: AddedallowOverwritetoArgsand theonBeforeGenerateTokenreturn value, so it flows through to the client upload token.client/VercelBlobClientUploadHandler.ts: AddedallowOverwritetoVercelBlobClientUploadHandlerExtrafor type consistency withaddRandomSuffix.Default behavior
allowOverwritedefaults tofalse, preserving the current behavior. No breaking changes.Commits
The two commits mirror the original PR (the second was added in response to @rchlfryn's review feedback on #16078):
feat(storage-vercel-blob): add allowOverwrite option— main changefix: pass allowOverwrite through to client handler— adds it toextraClientHandlerPropsand the client handler'sextratype for consistency