Skip to content

[Bug](s3StorageAdapater): getFilePrefix can return empty prefix during crop/save flow, causing 404 for freshly uploaded files #15989

@leonm93

Description

@leonm93

Describe the Bug

Affected area

packages/plugin-cloud-storage/src/utilities/getFilePrefix.ts

What happens

During upload -> crop/edit -> save, Payload may fetch the just-uploaded file via /api//file/ within the same create transaction

getFilePrefix() currently does:

use clientUploadContext.prefix if present
otherwise query DB (req.payload.find) by filename / sizes.*.filename
if nothing found, return ''

During create transaction req.payload.find will fail, so the file prefix is not found.

Symptoms

Failed to persist upload data for collection ... (warning in afterChange)
Failed to fetch file from http://localhost:3000/api/media/file/
GET /api/media/file/ 404

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/main/packages/plugin-cloud-storage/src/hooks/afterChange.ts

Reproduction Steps

Configure Payload with @payloadcms/storage-s3 (cloud-storage plugin) and an upload collection (e.g. media) that has:
non-empty prefix
crop: true
image sizes enabled
Open Payload Admin and create a new document in that upload collection.
Upload an image.
Use crop/edit controls.
Save immediately.

Which area(s) are affected?

plugin: cloud-storage

Environment Info

Binaries:
  Node: 22.18.0
  npm: 11.5.2
  Yarn: 1.22.22
  pnpm: 10.32.1
Relevant Packages:
  payload: 3.79.1
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:01 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T8103
  Available memory (MB): 8192
  Available CPU cores: 8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions