R2 storage from env + filename normalization
This commit is contained in:
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user