-
Notifications
You must be signed in to change notification settings - Fork 255
Open
Description
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
Labels
No labels