payloadcms / payloadcms/payload

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

Open
#15,989 2 comments 2 reactions 1 assignee View on GitHub

@r1tsuu is already working on this.

Since Sep 11, 2026.

Bug plugin: cloud-storage stale
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.