Skip to content

fix(plugin-cloud-storage): pass req to find in getFilePrefix for transaction support#16172

Open
Gdhanush-13 wants to merge 1 commit intopayloadcms:mainfrom
Gdhanush-13:fix/cloud-storage-get-file-prefix-transaction
Open

fix(plugin-cloud-storage): pass req to find in getFilePrefix for transaction support#16172
Gdhanush-13 wants to merge 1 commit intopayloadcms:mainfrom
Gdhanush-13:fix/cloud-storage-get-file-prefix-transaction

Conversation

@Gdhanush-13
Copy link
Copy Markdown

What

Fixes #15989 - getFilePrefix returns empty prefix during create transaction, causing crop/save flow to fail with Failed to persist upload data.

Root Cause

In packages/plugin-cloud-storage/src/utilities/getFilePrefix.ts, the req.payload.find() call on line 42 does not pass req. During a create operation, the document is being created within a transaction. Without req, the find query runs outside the transaction context and cannot see the uncommitted document, so it returns no results and the prefix resolves to an empty string ''.

Symptoms (as reported)

  • Failed to persist upload data for collection ... (warning in afterChange)
  • GET /api/media/file/<filename> returns 404
  • Crop/edit flow fails during initial upload when using S3 storage with a non-empty prefix

Fix

Added req to the find() call so the query participates in the same transaction and can see the just-created document:

 const files = await req.payload.find({
   collection: collection.slug,
   depth: 0,
   draft: true,
   limit: 1,
   pagination: false,
+  req,
   where: {

…saction support

During a create operation, getFilePrefix queries the database for the
document's prefix. Without passing req, the query runs outside the
current transaction and cannot see the uncommitted document, causing
the prefix to resolve to an empty string.

This leads to:
- 'Failed to persist upload data' warning in afterChange hook
- 404 when fetching /api/<collection>/file/<filename>
- Crop/edit flow failing during initial upload

Passing req ensures the find operation participates in the same
transaction context, allowing it to see the just-created document.

Fixes payloadcms#15989
@Gdhanush-13 Gdhanush-13 requested a review from denolfe as a code owner April 3, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant