R2 storage from env + filename normalization

This commit is contained in:
2026-08-27 12:45:47 +02:00
parent ed4a78b109
commit 5630765215
13 changed files with 145 additions and 11 deletions
+10 -3
View File
@@ -1,4 +1,5 @@
import type { Plugin } from 'payload'
import { s3Storage } from '@payloadcms/storage-s3'
/**
@@ -37,15 +38,21 @@ export const buildR2Storage = (collections: string[] = ['media']): Plugin => {
}
}
const collectionsConfig = Object.fromEntries(collections.map((slug) => [slug, true]))
// s3Storage wants Record<string, true> (the literal true, per collection),
// not Record<string, boolean>. Object.fromEntries widens true → boolean, so
// build the map with an explicitly-typed accumulator to keep the literal.
const collectionsConfig: Record<string, true> = {}
for (const slug of collections) {
collectionsConfig[slug] = true
}
return s3Storage({
collections: collectionsConfig,
bucket,
collections: collectionsConfig,
config: {
credentials: { accessKeyId, secretAccessKey },
endpoint,
region: 'auto', // R2 uses 'auto'
credentials: { accessKeyId, secretAccessKey },
// R2 requires path-style addressing for S3 compatibility.
forcePathStyle: true,
},