Skip to content

Multiple s3Storage instances share S3 client configuration #14175

@sharathsDev

Description

@sharathsDev

Describe the Bug

Description

When using two s3Storage plugin instances with different endpoints (e.g., AWS S3 and Cloudflare R2), the second plugin's endpoint configuration overwrites the first plugin's configuration, causing requests to use mixed endpoints.

Link to the code that reproduces this issue

private

Reproduction Steps

Configuration:

import { s3Storage } from '@payloadcms/storage-s3'

export default buildConfig({
  plugins: [
    // Plugin 1: AWS S3
    s3Storage({
      bucket: 'my-s3-bucket',
      collections: {
        fileupload: { /* ... */ },
        postmedia: { /* ... */ },
      },
      config: {
        credentials: { /* S3 credentials */ },
        endpoint: 'https://s3.us-east-1.amazonaws.com',
        region: 'us-east-1',
        forcePathStyle: true,
      },
    }),
    
    // Plugin 2: Cloudflare R2
    s3Storage({
      bucket: 'my-r2-bucket',
      collections: {
        media: { /* ... */ },
      },
      config: {
        credentials: { /* R2 credentials */ },
        endpoint: 'https://account-id.r2.cloudflarestorage.com',
        region: 'auto',
        forcePathStyle: true,
      },
    }),
  ],
})

Steps:

  1. Configure two s3Storage plugins as shown above
  2. Upload a file to the fileupload collection (first plugin)
  3. Observe the error

Expected Behavior

Each plugin instance should maintain its own isolated S3 client with independent endpoint configuration.

Actual Behavior

The upload request uses a mixed endpoint:

Host: my-s3-bucket.account-id.r2.cloudflarestorage.com

Error received:

ERROR: Access Denied
httpStatusCode: 403
servername: "my-s3-bucket.account-id.r2.cloudflarestorage.com"

The hostname incorrectly combines:

  • Bucket name from the first plugin (my-s3-bucket)
  • Endpoint from the second plugin (.r2.cloudflarestorage.com)

Which area(s) are affected? (Select all that apply)

plugin: storage-*

Environment Info

### Environment
- **Payload Version:** 3.58.0
- **@payloadcms/storage-s3 Version:**3.58.0
- **Node Version:** v22.20.0
- **Package Manager:** pnpm

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions