minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
920 stars 271 forks source link

Method makeBucket does not use MinioClient constructor's provided region #1292

Closed HunteRoi closed 3 months ago

HunteRoi commented 3 months ago

Hello, it seems that the makeBucket method is not using the region defined in the constructor of the MinioClient.

As implied by the types documentation, I shouldn't provide the region (also the whole API makes it obviousy we shouldn't).

So why doesn't it work as expected? I received the following error:

{
    "name":"S3Error",
    "code":"AuthorizationHeaderMalformed",
    "message":"The authorization header is malformed; the region is wrong; expecting 'eu-west-1'.",
    "bucketname":"mybucket",
    "resource":"/mybucket",
    "region":"eu-west-1",
    "requestid":"17CE946273A06571",
    "hostid":"dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8",
    "amzRequestid":"17CE946273A06571",
    "amzId2":"dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8",
    "amzBucketRegion":"eu-west-1"
}

Context

Code used

const minioClient = new MinioClient({
    endPoint: env.MINIO_ENDPOINT,
    port: env.MINIO_PORT,
    useSSL: false,
    accessKey: env.MINIO_ACCESS_KEY,
    secretKey: env.MINIO_SECRET_KEY,
    region: env.MINIO_REGION,
});

const bucketExists = await minioClient.bucketExists(env.MINIO_BUCKET);
if (!bucketExists) {
    await minioClient.makeBucket(env.MINIO_BUCKET); // fails
}
await minioClient.putObject(env.MINIO_BUCKET, id, payload.image);

Quick fix

await minioClient.makeBucket(env.MINIO_BUCKET, env.MINIP_REGION); // works

How I knew what to do

My team and I checked your code and we saw that there's a difference between what we have in our VSCode typing docs and what is wrote here: https://github.com/minio/minio-js/blob/6b916367ec13283b950d5932825e669a344d11ce/src/internal/client.ts#L849

image

cc @drakexorn @MRGoose70

prakashsvmx commented 3 months ago

Thank you for reporting, we will check and send a fix

HunteRoi commented 3 months ago

@prakashsvmx can you tell me when is the next release planned by the way?

prakashsvmx commented 3 months ago

We have few more APIs to be migrated to TS. So no fixed ETA.