From fc976b9e6323330f4b30d029c23ddff0d8320c6e Mon Sep 17 00:00:00 2001 From: Prakash Senthil Vel <23444145+prakashsvmx@users.noreply.github.com> Date: Mon, 13 May 2024 22:33:41 +0530 Subject: [PATCH] fix use configured region from constructor for makebucket (#1293) --- README.md | 2 +- README_zh_CN.md | 2 +- examples/{make-bucket.js => make-bucket.mjs} | 5 +++++ src/internal/client.ts | 7 +++---- 4 files changed, 10 insertions(+), 6 deletions(-) rename examples/{make-bucket.js => make-bucket.mjs} (91%) diff --git a/README.md b/README.md index c48a7195..9cde67a9 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ The complete API Reference is available here: - [list-objects-v2.js](https://github.com/minio/minio-js/blob/master/examples/list-objects-v2.js) - [list-objects-v2-with-metadata.js](https://github.com/minio/minio-js/blob/master/examples/list-objects-v2-with-metadata.js) (Extension) - [bucket-exists.mjs](https://github.com/minio/minio-js/blob/master/examples/bucket-exists.mjs) -- [make-bucket.js](https://github.com/minio/minio-js/blob/master/examples/make-bucket.js) +- [make-bucket.mjs](https://github.com/minio/minio-js/blob/master/examples/make-bucket.js) - [remove-bucket.mjs](https://github.com/minio/minio-js/blob/master/examples/remove-bucket.mjs) - [list-incomplete-uploads.js](https://github.com/minio/minio-js/blob/master/examples/list-incomplete-uploads.js) - [get-bucket-versioning.mjs](https://github.com/minio/minio-js/blob/master/examples/get-bucket-versioning.js) diff --git a/README_zh_CN.md b/README_zh_CN.md index a792f7f9..f8f2b8f8 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -155,7 +155,7 @@ mc ls play/europetrip/ * [list-objects.js](https://github.com/minio/minio-js/blob/master/examples/list-objects.js) * [list-objects-v2.js](https://github.com/minio/minio-js/blob/master/examples/list-objects-v2.js) * [bucket-exists.mjs](https://github.com/minio/minio-js/blob/master/examples/bucket-exists.mjs) -* [make-bucket.js](https://github.com/minio/minio-js/blob/master/examples/make-bucket.js) +* [make-bucket.mjs](https://github.com/minio/minio-js/blob/master/examples/make-bucket.js) * [remove-bucket.mjs](https://github.com/minio/minio-js/blob/master/examples/remove-bucket.mjs) * [list-incomplete-uploads.js](https://github.com/minio/minio-js/blob/master/examples/list-incomplete-uploads.js) diff --git a/examples/make-bucket.js b/examples/make-bucket.mjs similarity index 91% rename from examples/make-bucket.js rename to examples/make-bucket.mjs index bb0389d8..eca9fe55 100644 --- a/examples/make-bucket.js +++ b/examples/make-bucket.mjs @@ -24,6 +24,11 @@ const s3Client = new Minio.Client({ accessKey: 'YOUR-ACCESSKEYID', secretKey: 'YOUR-SECRETACCESSKEY', }) + +// Create a bucket name my-bucketname-nr. +await s3Client.makeBucket('my-bucketname-nr') +console.log('Success') + // Create a bucket name my-bucketname. await s3Client.makeBucket('my-bucketname', 'us-west-1') diff --git a/src/internal/client.ts b/src/internal/client.ts index 3b6e26fe..7b028903 100644 --- a/src/internal/client.ts +++ b/src/internal/client.ts @@ -892,10 +892,9 @@ export class TypedClient { headers['x-amz-bucket-object-lock-enabled'] = true } - if (!region) { - region = DEFAULT_REGION - } - const finalRegion = region // type narrow + // For custom region clients default to custom region specified in client constructor + const finalRegion = this.region || region || DEFAULT_REGION + const requestOpt: RequestOption = { method, bucketName, headers } try {