diff --git a/packages/storage-driver-s3/src/index.test.ts b/packages/storage-driver-s3/src/index.test.ts index fb09921886..7297f6e559 100644 --- a/packages/storage-driver-s3/src/index.test.ts +++ b/packages/storage-driver-s3/src/index.test.ts @@ -12,6 +12,7 @@ import { normalizePath } from '@directus/utils'; import { isReadableStream } from '@directus/utils/node'; import { randAlphaNumeric, + randBoolean, randDirectoryPath, randDomainName, randFilePath, @@ -71,6 +72,7 @@ beforeEach(() => { root: randDirectoryPath(), endpoint: randDomainName(), region: randWord(), + forcePathStyle: randBoolean(), }, path: { input: randUnique() + randFilePath(), @@ -192,7 +194,6 @@ describe('#constructor', () => { }); expect(S3Client).toHaveBeenCalledWith({ - forcePathStyle: true, endpoint: { hostname: sampleDomain, protocol: 'http:', @@ -217,7 +218,6 @@ describe('#constructor', () => { }); expect(S3Client).toHaveBeenCalledWith({ - forcePathStyle: true, endpoint: { hostname: sampleDomain, protocol: 'https:', @@ -247,6 +247,23 @@ describe('#constructor', () => { }); }); + test('Sets force path style', () => { + new DriverS3({ + key: sample.config.key, + secret: sample.config.secret, + bucket: sample.config.bucket, + forcePathStyle: sample.config.forcePathStyle, + }); + + expect(S3Client).toHaveBeenCalledWith({ + forcePathStyle: sample.config.forcePathStyle, + credentials: { + accessKeyId: sample.config.key, + secretAccessKey: sample.config.secret, + }, + }); + }); + test('Normalizes config path when root is given', () => { const mockRoot = randDirectoryPath(); diff --git a/packages/storage-driver-s3/src/index.ts b/packages/storage-driver-s3/src/index.ts index f5c1c9eda9..a6f923199b 100644 --- a/packages/storage-driver-s3/src/index.ts +++ b/packages/storage-driver-s3/src/index.ts @@ -29,6 +29,7 @@ export type DriverS3Config = { serverSideEncryption?: string; endpoint?: string; region?: string; + forcePathStyle?: boolean; }; export class DriverS3 implements Driver { @@ -61,14 +62,16 @@ export class DriverS3 implements Driver { protocol, path: '/', }; - - s3ClientConfig.forcePathStyle = true; } if (config.region) { s3ClientConfig.region = config.region; } + if (config.forcePathStyle !== undefined) { + s3ClientConfig.forcePathStyle = config.forcePathStyle; + } + this.client = new S3Client(s3ClientConfig); this.bucket = config.bucket; this.acl = config.acl;