CSharp-Single-EFCore/Bunny.Common/Connect/MinioContext.cs

31 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Bunny.Common.Utils;
using Microsoft.AspNetCore.Builder;
using Minio;
namespace Bunny.Common.Connect;
public static class MinioContext
{
public static IMinioClient? MinioClient;
public static readonly string BucketName = AppSettings.GetConfig("Minio:BucketName");
public static void AddMinioContext(this WebApplicationBuilder builder)
{
var endpoint = AppSettings.GetConfig("Minio:Url");
var accessKey = AppSettings.GetConfig("Minio:AccessKey");
var secretKey = AppSettings.GetConfig("Minio:SecretKey");
MinioClient = new MinioClient().WithEndpoint(endpoint).WithCredentials(accessKey, secretKey)
// .WithSSL() // 使用HTTPS
.Build();
Task.Run(ShowAllBucket);
}
private static async Task ShowAllBucket()
{
var listBucketsAsync = await MinioUtil.ListBucketsAsync();
foreach (var bucket in listBucketsAsync.Buckets) Console.WriteLine($"Minio存在的桶{bucket.Name}");
Console.WriteLine("Minio 连接成功...");
}
}