Repository navigation
Description
Describe the Bug
With @payloadcms/storage-vercel-blob and addRandomSuffix: true, the answer of a create, and of a file replacement, carries the new filename with the url of the name before the suffix:
filename: photo-D2Ap3L30Q4GueEBLM5kWlAYEErlBZB.jpg
url: https://<store>.public.blob.vercel-storage.com/photo.jpg
No file exists at that URL, it gives 404. The database is right, and a later read of the document gives the right url. So a client that uses the answer of its own request gets a dead link.
The collection has no image sizes. #9589 reports missing image sizes with the same option, and a comment there names the same cause. This report shows that the cause also breaks a collection with no image sizes, and it comes with a reproduction.
The cause, in two steps:
-
In
packages/storage-vercel-blob/src/adapter.ts,handleUploadsets the new name on the document it was given, and returns the whole document. That document already holds aurlbuilt from the first name.if (result.filename) { data.filename = result.filename } return data
-
In
packages/plugin-cloud-storage/src/hooks/afterChange.ts, the hook merges whathandleUploadreturns, saves it, and returns{ ...doc, ...uploadMetadata }. The answer then has the newfilenameand the oldurl.
Expected: the answer carries the url of the stored file, the one a later read gives.
Why a site turns addRandomSuffix on: without it, a replaced or deleted file frees its name, and the next file with that name lands at the old URL, which browsers and the CDN may have cached for a long time. Payload checks a new name against the database only.
Link to the code that reproduces this issue
Reproduction Steps
- Clone the repository.
cp .env.example .env, then fill inDATABASE_URL,PAYLOAD_SECRETand a Vercel BlobBLOB_READ_WRITE_TOKENof a public store. pnpm installpnpm check
The script creates a document with the local API, then replaces its file. Each time, it fetches the url of the answer and the url of a later read:
DEAD create answer HTTP 404 photo-D2Ap3L30Q4GueEBLM5kWlAYEErlBZB.jpg https://<store>.public.blob.vercel-storage.com/photo.jpg
ok create later read HTTP 200 photo-D2Ap3L30Q4GueEBLM5kWlAYEErlBZB.jpg https://<store>.public.blob.vercel-storage.com/photo-D2Ap3L30Q4GueEBLM5kWlAYEErlBZB.jpg
DEAD replace answer HTTP 404 photo-LuZRYeK418OOLu6JRa9wUEZUaffBeI.jpg https://<store>.public.blob.vercel-storage.com/photo.jpg
ok replace later read HTTP 200 photo-LuZRYeK418OOLu6JRa9wUEZUaffBeI.jpg https://<store>.public.blob.vercel-storage.com/photo-LuZRYeK418OOLu6JRa9wUEZUaffBeI.jpg
The collection has disablePayloadAccessControl: true, so that url is the file's URL in the store and the script can fetch it with no server running.
The same happens over REST: with pnpm dev running, a POST /api/media with fixtures/photo.jpg answers with the new filename and a url that ends with /photo.jpg.
Which area(s) are affected?
plugin: cloud-storage, plugin: storage-*
Environment Info
Binaries:
Node: 24.21.0
npm: 11.19.0
Yarn: 1.22.22
pnpm: 9.15.9
Relevant Packages:
payload: 3.90.2
next: 16.3.3
@payloadcms/db-mongodb: 3.90.2
@payloadcms/graphql: 3.90.2
@payloadcms/next/utilities: 3.90.2
@payloadcms/plugin-cloud-storage: 3.90.2
@payloadcms/richtext-lexical: 3.90.2
@payloadcms/storage-vercel-blob: 3.90.2
@payloadcms/translations: 3.90.2
@payloadcms/ui/shared: 3.90.2
react: 19.2.6
react-dom: 19.2.6
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.6.0
Available memory (MB): 32768
Available CPU cores: 10
Activity
fix(plugin-cloud-storage): return updatedDoc from afterChange to refl…
fix(storage-vercel-blob): keep image-size filenames separate with add…
chore: resolve six more Payload upload, query and block regressions