fix(plugin-cloud-storage): missing 'prefix' in cloud storage plugin #11970
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue reproduction
In the community folder, enable versioning for the media collection and install the
s3storage
plugin (see Git patch). I useminio
to have a local S3 compatible backend and then I run the app with:AWS_ACCESS_KEY_ID=minioadmin AWS_SECRET_ACCESS_KEY=minioadmin START_MEMORY_DB=true pnpm dev _community
.Next, open the media collection and create a new entry. Then open that entry, remove the file it currently has, and upload a new file. Save as draft.
Now the media can no longer be accessed and the thumbnails are broken.
If you make an edit but save it by publishing the issue goes away. I also couldn't reproduce this by adding a text field, changing that, and saving the document as draft.
Screen recording
issue.mov
Fix
We were able to narrow it down to this call
payload/packages/plugin-cloud-storage/src/utilities/getFilePrefix.ts
Lines 26 to 41 in 816fb28
Adding
draft: true
fixes the issue. It seems that theprefix
can only be found in a draft, and withoutdraft: true
those drafts aren't searched. What I don't understand is why adding a text field, changing its value, and saving that as draft, doesn't cause any problems though. I'd assume that changing a field and uploading a new file results in the same outcome: a new version stored in the versions collection.Maybe it's clear to you why it behaves like this.