Skip to content

.WithRegion stopped working after upgrading from 6.0.4 to 6.0.5 #1331

@2048khz-gachi-rmx

Description

@2048khz-gachi-rmx

Setup via DI (some code omitted for brevity):

public static class DependencyInjection
{
    public static IServiceCollection AddFileUploader(this IServiceCollection services, IConfigurationSection settings)
    {
        var minioSettings = settings.Get<MinioSettings>()!;

        // values obtained via debugger:
        services.AddMinio(cfg => cfg
            .WithEndpoint(minioSettings.BaseUrl) // URI "https://s3.mydomain.net/"
            .WithRegion(minioSettings.Region) // string "us-west-1"
            .WithCredentials(minioSettings.AccessKey, minioSettings.SecretKey));
        
        return services;
    }
}

Usage:

public class MinioUploadService(IMinioClient minioClient, MinioSettings minioSettings)
{
    public async Task<Uri> UploadFile(Stream stream, long fileSize, string? filename, string? contentType, CancellationToken token)
    {
        var resp = await minioClient.PutObjectAsync(new PutObjectArgs()
            .WithBucket(minioSettings.BucketName)
            .WithObject(filename)
            .WithContentType(contentType)
            .WithObjectSize(fileSize)
            .WithStreamData(stream), token);
        
        var publicLink = new Uri(
            new Uri(minioClient.Config.Endpoint, UriKind.Absolute),
            $"{minioSettings.BucketName}/{WebUtility.UrlEncode(resp.ObjectName)}");
        
        return publicLink;
    }
    // ...

In 6.0.4, uploading works fine. In 6.0.5, this will throw:

Minio.Exceptions.UnexpectedMinioException: MinIO API responded with message=The authorization header is malformed; the region is wrong; expecting 'us-west-1'.
   at Minio.MinioClient.ParseErrorFromContent(ResponseResult response)
   at Minio.MinioClient.ParseError(ResponseResult response)
   at Minio.Handlers.DefaultErrorHandler.Handle(ResponseResult response)
   at Minio.RequestExtensions.ExecuteTaskAsync(IMinioClient minioClient, HttpRequestMessageBuilder requestMessageBuilder, Type ignoreExceptionType, Boolean isSts, CancellationToken cancellationToken)
   at Minio.MinioClient.NewMultipartUploadAsync(NewMultipartUploadPutArgs args, CancellationToken cancellationToken)
   at Minio.MinioClient.PutObjectAsync(PutObjectArgs args, CancellationToken cancellationToken)

Inspecting the minioClient, minioClient.Config.Region becomes us-east-1 for some reason.

Metadata

Metadata

Assignees

No one assigned

    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