feat(storage-vercel-blob): add allowOverwrite option#16078
feat(storage-vercel-blob): add allowOverwrite option#16078joeliomartini 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
|
+1 Nice work — this is exactly what we need. We're currently carrying a local pnpm patch with the same changes. One thing I noticed: the The fix would be two additions:
extraClientHandlerProps: (collection) => ({
addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
allowOverwrite: !!optionsWithDefaults.allowOverwrite, // add this
baseURL: baseUrl,
prefix: ...
}),
extra: { addRandomSuffix, allowOverwrite, baseURL, prefix = '' },The |
Adds allowOverwrite to extraClientHandlerProps and the VercelBlobClientUploadHandler type/destructuring for consistency with addRandomSuffix.
|
Thanks for catching that @rchlfryn — great eye. Just pushed a fix that adds Good to know you're carrying the same patch locally — hopefully this gets merged soon so we can all drop it! |
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.