Skip to content

fix(plugin-cloud-storage): clear stale uploadEdits before metadata persistence update - #17848

Open
AlgoArtist06 wants to merge 1 commit into
payloadcms:mainfrom
AlgoArtist06:fix/15991-clear-upload-edits-before-metadata-persist
Open

fix(plugin-cloud-storage): clear stale uploadEdits before metadata persistence update#17848
AlgoArtist06 wants to merge 1 commit into
payloadcms:mainfrom
AlgoArtist06:fix/15991-clear-upload-edits-before-metadata-persist

Conversation

@AlgoArtist06

Copy link
Copy Markdown

What?

When a document is saved with a crop (or any resize/focal-point edit) via the @payloadcms/plugin-cloud-storage plugin, the whole upload fails.

The plugin's afterChange hook uploads the file to the adapter and then persists the adapter's returned metadata through a nested req.payload.update() that reuses the original req. Before that call it clears req.file and req.payloadUploadSizes to prevent re-processing, but it leaves req.query.uploadEdits intact.

Payload's generateFileData reads uploadEdits straight from req.query on every update and returns true from shouldReupload() whenever a crop/resize/focal change is present. So the metadata-persistence update re-enters the full file re-processing path and re-crops the already-cropped file. On recent versions this surfaces as an HTTP 400 (BadRequestError: There was a problem while uploading the file / extract_area: bad extract area); on older versions it fails with a FileRetrievalError while trying to re-fetch the just-created file by URL.

Why?

The uploadEdits in req.query describe the edits applied to the original file. They have already been consumed by the first pass of generateFileData before the hook runs, so they must not be re-applied to the already-processed file by the plugin's internal metadata update. The leak turns a supposedly data-only metadata persistence call into a second image edit.

How?

In getAfterChangeHook, alongside the existing req.file = undefined / req.payloadUploadSizes = undefined cleanup, drop the already-consumed uploadEdits from req.query before the nested req.payload.update(). This matches the suggested fix from the issue and keeps the metadata persistence data-only.

Added a focused integration regression test (test/plugin-cloud-storage/crop-repro.int.spec.ts) that creates a crop-edited upload through the plugin with an in-memory adapter and asserts the document persists successfully with the adapter metadata. The test boots a lightweight config that needs no Docker/localstack and reproduces the failure without the fix.

Fixes #15991


Automated by pr-pipeline (com.ashutosh.prpipeline).

…rsistence update

The afterChange hook's nested req.payload.update reuses the original req, which still carries req.query.uploadEdits from the first request. generateFileData re-reads those edits and re-enters the file re-processing path, re-cropping the already-cropped file on every crop upload, which fails with a BadRequestError or FileRetrievalError. Clear uploadEdits alongside req.file and req.payloadUploadSizes so the metadata persistence update stays data-only.

Fixes payloadcms#15991
@AlgoArtist06
AlgoArtist06 requested a review from denolfe as a code owner August 19, 2026 05:40
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.

cropping image on create fails with "Failed to persist upload data"

1 participant