Skip to content

Image Resizing Fails When addRandomSuffix: true in vercelBlobStorage Configuration #9589

Closed

Description

@mednet-ecrep

Describe the Bug

When uploading images in various sizes, only the original image file with its original dimensions is created.
All other image sizes are not generated and remain empty.

This issue occurs only when the addRandomSuffix: true option is enabled in the vercelBlobStorage configuration.
When the addRandomSuffix option is removed, the functionality works as expected.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/main/templates/with-vercel-website

Reproduction Steps

Add addRandomSuffix: true to the vercelBlobStorage config inside the payload config file.
Then login to the backend, navigate to the media collection and try to upload some image.

Which area(s) are affected? (Select all that apply)

plugin: other

Environment Info

payload: 3.2.1
  next: 15.0.3
  @payloadcms/db-mongodb: 3.2.1
  @payloadcms/email-resend: 3.2.1
  @payloadcms/graphql: 3.2.1
  @payloadcms/live-preview: 3.2.1
  @payloadcms/live-preview-react: 3.2.1
  @payloadcms/next/utilities: 3.2.1
  @payloadcms/plugin-cloud-storage: 3.2.1
  @payloadcms/plugin-form-builder: 3.2.1
  @payloadcms/plugin-nested-docs: 3.2.1
  @payloadcms/plugin-seo: 3.2.1
  @payloadcms/richtext-lexical: 3.2.1
  @payloadcms/storage-vercel-blob: 3.2.1
  @payloadcms/translations: 3.2.1
  @payloadcms/ui/shared: 3.2.1
  react: 19.0.0-rc-65a56d0e-20241020
  react-dom: 19.0.0-rc-65a56d0e-20241020

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Nov 28, 2024
  2. removed
    validate-reproduction
    on Nov 28, 2024
  3. self-assigned this
    on Apr 1, 2025
  4. removed
    status: needs-triage
    on Apr 1, 2025
  5. PatrikKozak commented on Apr 1, 2025

    @PatrikKozak
    Contributor

    Hey @mednet-ecrep,

    Thanks for your patience here!

    Can you confirm if this issue is still happening on your end?

    I wasn't able to reproduce it on my initial testings

  6. Crayonan commented on May 7, 2025

    @Crayonan

    @PatrikKozak

    I am also running into this exact problem, when I change the random suffix to false this solved the problem of resizing.

  7. marcosdipaolo commented on Jul 16, 2025

    @marcosdipaolo

    it's been a couple of months but I just had the issue. Using vercel blob, the random suffix gets added to the img url in vercel blob but the url is stored in the db without the suffix, hence they are 404'ing

  8. donbellamy commented on Apr 28, 2026

    @donbellamy

    Just confirming this is still an issue. Thanks!

  9. Toti91 commented on Jul 2, 2026

    @Toti91

    Still running into this issue.

  10. jmtorres commented on Jul 31, 2026

    @jmtorres

    Encountered this on @payloadcms/[email protected] / @payloadcms/[email protected]. I diffed the relevant files against 3.87.0 (current latest) and they're unchanged, so it should still be present there — though I haven't run it on 3.87.0 to confirm. Here's the mechanism, plus a possible explanation for the earlier non-repro.

    Root cause

    adapter.js mutates the shared document object on every upload:

    handleUpload: async ({ data, file: { buffer, filename, mimeType } }) => {
      const result = await uploadFile({ ..., addRandomSuffix, filename, ... })
      if (result.filename) {
        data.filename = result.filename   // `data` is the doc, shared by all files
      }
      return data                         // returns the whole doc, not a per-file patch
    }

    plugin-cloud-storage's getAfterChangeHook calls that for the original and every image size concurrently, then collapses the results last-write-wins:

    const uploadResults = await Promise.all(
      files.filter((file) => !file.clientUploadContext)
           .map((file) => adapter.handleUpload({ ..., data: doc, file, ... }))
    )
    const uploadMetadata = uploadResults
      .filter((r) => r != null && typeof r === 'object')
      .reduce((acc, metadata) => ({ ...acc, ...metadata }), {})
    // ... payload.update({ data: uploadMetadata })

    Every element of uploadResults is the same object reference, so uploadMetadata.filename is whichever upload resolved last. Two consequences:

    1. The document's top-level filename/url point at one of the resized variants, not the original.
    2. No sizes.*.filename is ever updated with its own random suffix, so every variant URL 404s — those blobs exist under randomized names nothing references, and the true original is orphaned entirely.

    A resulting row (source image 1080×1350):

    field stored value blob
    filename Foo-500x500-<random suffix>.png 200
    sizes.thumbnail.filename Foo-300x375.png 404
    sizes.adminThumbnail.filename Foo-240x300.png 404
    original Foo.png 404

    A possible explanation for the non-repro

    @PatrikKozak — this may be why it didn't reproduce during triage: the discriminator looks like imageSizes rather than the storage mode. Without imageSizes — or anywhere sharp isn't producing sizes — files has a single entry, so there's no race, data.filename correctly receives the randomized original name, and everything works. Might be worth re-checking whether the collection under test had an imageSizes array.

    clientUploads doesn't avoid it — it makes it deterministic

    getIncomingFiles sets clientUploadContext only on mainFile; the size entries never get it. So files.filter((file) => !file.clientUploadContext) skips only the original, and the sizes still upload server-side in both modes. Size generation itself is unconditional — generateFileData.js gates it on fileSupportsResize && imageSizes only, and under clientUploads the server re-downloads the blob to rebuild the buffer for sharp.

    • clientUploads: false — the original is in the race, so it occasionally wins and filename survives.
    • clientUploads: true — the original is filtered out, so a variant always wins.

    Variant URLs are broken either way.

    Suggested direction

    handleUpload returning the mutated doc is what makes the merge unsafe. Returning a per-file patch — { filename } for the main file, { sizes: { [size]: { filename } } } for a size — and deep-merging would fix both halves. That requires handleUpload to know which size it's handling; getIncomingFiles already knows and could pass it through.

  11. added a commit that references this issue on Oct 23, 2026
    8282414
  12. github-actions commented on Oct 27, 2026

    @github-actions
    Contributor

    🚀 This is included in version v3.92.1

  13. nathanlentz commented on Oct 29, 2026

    @nathanlentz
    Collaborator

    Addressed in #18920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions