Skip to content

Commit 0d10f43

Browse files
authored
fix(plugin-cloud-storage): missing 'prefix' in cloud storage plugin (#11970)
## Fix We were able to narrow it down to this call https://github.com/payloadcms/payload/blob/816fb28f552dfefc11704c7b379ca7fb31abd687/packages/plugin-cloud-storage/src/utilities/getFilePrefix.ts#L26-L41 Adding `draft: true` fixes the issue. It seems that the `prefix` can only be found in a draft, and without `draft: true` those drafts aren't searched. ### Issue reproduction In the community folder, enable versioning for the media collection and install the `s3storage` plugin (see Git patch). I use `minio` 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. ```diff diff --git test/_community/collections/Media/index.ts test/_community/collections/Media/index.ts index bb5edd0..689423053c 100644 --- test/_community/collections/Media/index.ts +++ test/_community/collections/Media/index.ts @@ -9,6 +9,9 @@ export const MediaCollection: CollectionConfig = { read: () => true, }, fields: [], + versions: { + drafts: true, + }, upload: { crop: true, focalPoint: true, diff --git test/_community/config.ts test/_community/config.ts index ee1aee6..c81ec5f933 100644 --- test/_community/config.ts +++ test/_community/config.ts @@ -7,6 +7,7 @@ import { devUser } from '../credentials.js' import { MediaCollection } from './collections/Media/index.js' import { PostsCollection, postsSlug } from './collections/Posts/index.js' import { MenuGlobal } from './globals/Menu/index.js' +import { s3Storage } from '@payloadcms/storage-s3' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -24,6 +25,21 @@ export default buildConfigWithDefaults({ // ...add more globals here MenuGlobal, ], + plugins: [ + s3Storage({ + enabled: true, + bucket: 'amboss', + config: { + region: 'eu-west-1', + endpoint: 'http://localhost:9000', + }, + collections: { + media: { + prefix: 'media', + }, + }, + }), + ], onInit: async (payload) => { await payload.create({ collection: 'users', ``` ## Screen recording https://github.com/user-attachments/assets/b13be4a3-e858-427a-8bfa-6592b87748ee
1 parent dcd4e37 commit 0d10f43

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export async function getFilePrefix({
2626
const files = await req.payload.find({
2727
collection: collection.slug,
2828
depth: 0,
29+
draft: true,
2930
limit: 1,
3031
pagination: false,
3132
where: {

0 commit comments

Comments
 (0)